summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README39
-rw-r--r--examples/animation/README38
-rw-r--r--examples/animation/animatedtiles/animatedtiles.pro13
-rw-r--r--examples/animation/animatedtiles/animatedtiles.qrc11
-rw-r--r--examples/animation/animatedtiles/images/Time-For-Lunch-2.jpgbin0 -> 32471 bytes
-rw-r--r--examples/animation/animatedtiles/images/centered.pngbin0 -> 892 bytes
-rw-r--r--examples/animation/animatedtiles/images/ellipse.pngbin0 -> 10767 bytes
-rw-r--r--examples/animation/animatedtiles/images/figure8.pngbin0 -> 14050 bytes
-rw-r--r--examples/animation/animatedtiles/images/kinetic.pngbin0 -> 6776 bytes
-rw-r--r--examples/animation/animatedtiles/images/random.pngbin0 -> 14969 bytes
-rw-r--r--examples/animation/animatedtiles/images/tile.pngbin0 -> 16337 bytes
-rw-r--r--examples/animation/animatedtiles/main.cpp256
-rw-r--r--examples/animation/animation.pro15
-rw-r--r--examples/animation/appchooser/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/animation/appchooser/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/animation/appchooser/appchooser.pro13
-rw-r--r--examples/animation/appchooser/appchooser.qrc8
-rw-r--r--examples/animation/appchooser/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/animation/appchooser/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/animation/appchooser/main.cpp157
-rw-r--r--examples/animation/easing/animation.h100
-rw-r--r--examples/animation/easing/easing.pro19
-rw-r--r--examples/animation/easing/easing.qrc5
-rw-r--r--examples/animation/easing/form.ui201
-rw-r--r--examples/animation/easing/images/qt-logo.pngbin0 -> 5149 bytes
-rw-r--r--examples/animation/easing/main.cpp52
-rw-r--r--examples/animation/easing/window.cpp176
-rw-r--r--examples/animation/easing/window.h78
-rw-r--r--examples/animation/moveblocks/main.cpp319
-rw-r--r--examples/animation/moveblocks/moveblocks.pro12
-rw-r--r--examples/animation/states/accessories-dictionary.pngbin0 -> 5396 bytes
-rw-r--r--examples/animation/states/akregator.pngbin0 -> 4873 bytes
-rw-r--r--examples/animation/states/digikam.pngbin0 -> 3334 bytes
-rw-r--r--examples/animation/states/help-browser.pngbin0 -> 6984 bytes
-rw-r--r--examples/animation/states/k3b.pngbin0 -> 8220 bytes
-rw-r--r--examples/animation/states/kchart.pngbin0 -> 4887 bytes
-rw-r--r--examples/animation/states/main.cpp271
-rw-r--r--examples/animation/states/states.pro13
-rw-r--r--examples/animation/states/states.qrc10
-rw-r--r--examples/animation/stickman/animation.cpp192
-rw-r--r--examples/animation/stickman/animation.h82
-rw-r--r--examples/animation/stickman/animations/chillingbin0 -> 6508 bytes
-rw-r--r--examples/animation/stickman/animations/dancingbin0 -> 2348 bytes
-rw-r--r--examples/animation/stickman/animations/deadbin0 -> 268 bytes
-rw-r--r--examples/animation/stickman/animations/jumpingbin0 -> 1308 bytes
-rw-r--r--examples/animation/stickman/graphicsview.cpp57
-rw-r--r--examples/animation/stickman/graphicsview.h63
-rw-r--r--examples/animation/stickman/lifecycle.cpp213
-rw-r--r--examples/animation/stickman/lifecycle.h79
-rw-r--r--examples/animation/stickman/main.cpp101
-rw-r--r--examples/animation/stickman/node.cpp92
-rw-r--r--examples/animation/stickman/node.h70
-rw-r--r--examples/animation/stickman/stickman.cpp337
-rw-r--r--examples/animation/stickman/stickman.h103
-rw-r--r--examples/animation/stickman/stickman.pro24
-rw-r--r--examples/animation/stickman/stickman.qrc8
-rw-r--r--examples/dbus/complexpingpong/complexping.cpp117
-rw-r--r--examples/dbus/complexpingpong/complexping.h58
-rw-r--r--examples/dbus/complexpingpong/complexping.pro18
-rw-r--r--examples/dbus/complexpingpong/complexpingpong.pro4
-rw-r--r--examples/dbus/complexpingpong/complexpong.cpp104
-rw-r--r--examples/dbus/complexpingpong/complexpong.h67
-rw-r--r--examples/dbus/complexpingpong/complexpong.pro18
-rw-r--r--examples/dbus/complexpingpong/ping-common.h41
-rw-r--r--examples/dbus/dbus-chat/chat.cpp163
-rw-r--r--examples/dbus/dbus-chat/chat.h81
-rw-r--r--examples/dbus/dbus-chat/chat_adaptor.cpp74
-rw-r--r--examples/dbus/dbus-chat/chat_adaptor.h96
-rw-r--r--examples/dbus/dbus-chat/chat_interface.cpp64
-rw-r--r--examples/dbus/dbus-chat/chat_interface.h88
-rw-r--r--examples/dbus/dbus-chat/chatmainwindow.ui185
-rw-r--r--examples/dbus/dbus-chat/chatsetnickname.ui149
-rw-r--r--examples/dbus/dbus-chat/com.trolltech.chat.xml15
-rw-r--r--examples/dbus/dbus-chat/dbus-chat.pro21
-rw-r--r--examples/dbus/dbus.pro17
-rw-r--r--examples/dbus/listnames/listnames.cpp91
-rw-r--r--examples/dbus/listnames/listnames.pro19
-rw-r--r--examples/dbus/pingpong/ping-common.h41
-rw-r--r--examples/dbus/pingpong/ping.cpp74
-rw-r--r--examples/dbus/pingpong/ping.pro18
-rw-r--r--examples/dbus/pingpong/pingpong.pro4
-rw-r--r--examples/dbus/pingpong/pong.cpp79
-rw-r--r--examples/dbus/pingpong/pong.h53
-rw-r--r--examples/dbus/pingpong/pong.pro18
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.cpp137
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.h73
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.pro22
-rw-r--r--examples/dbus/remotecontrolledcar/car/car.xml11
-rw-r--r--examples/dbus/remotecontrolledcar/car/car_adaptor.cpp98
-rw-r--r--examples/dbus/remotecontrolledcar/car/car_adaptor.h96
-rw-r--r--examples/dbus/remotecontrolledcar/car/main.cpp72
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car.xml11
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car_interface.cpp64
-rw-r--r--examples/dbus/remotecontrolledcar/controller/car_interface.h113
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.cpp82
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.h69
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.pro23
-rw-r--r--examples/dbus/remotecontrolledcar/controller/controller.ui64
-rw-r--r--examples/dbus/remotecontrolledcar/controller/main.cpp52
-rw-r--r--examples/dbus/remotecontrolledcar/remotecontrolledcar.pro10
-rw-r--r--examples/desktop/README41
-rw-r--r--examples/desktop/desktop.pro13
-rw-r--r--examples/desktop/screenshot/main.cpp51
-rw-r--r--examples/desktop/screenshot/screenshot.cpp197
-rw-r--r--examples/desktop/screenshot/screenshot.h99
-rw-r--r--examples/desktop/screenshot/screenshot.pro11
-rw-r--r--examples/dialogs/README40
-rw-r--r--examples/dialogs/classwizard/classwizard.cpp430
-rw-r--r--examples/dialogs/classwizard/classwizard.h156
-rw-r--r--examples/dialogs/classwizard/classwizard.pro12
-rw-r--r--examples/dialogs/classwizard/classwizard.qrc11
-rw-r--r--examples/dialogs/classwizard/images/background.pngbin0 -> 22578 bytes
-rw-r--r--examples/dialogs/classwizard/images/banner.pngbin0 -> 3947 bytes
-rw-r--r--examples/dialogs/classwizard/images/logo1.pngbin0 -> 1619 bytes
-rw-r--r--examples/dialogs/classwizard/images/logo2.pngbin0 -> 1619 bytes
-rw-r--r--examples/dialogs/classwizard/images/logo3.pngbin0 -> 1619 bytes
-rw-r--r--examples/dialogs/classwizard/images/watermark1.pngbin0 -> 14516 bytes
-rw-r--r--examples/dialogs/classwizard/images/watermark2.pngbin0 -> 14912 bytes
-rw-r--r--examples/dialogs/classwizard/main.cpp63
-rw-r--r--examples/dialogs/configdialog/configdialog.cpp116
-rw-r--r--examples/dialogs/configdialog/configdialog.h69
-rw-r--r--examples/dialogs/configdialog/configdialog.pro16
-rw-r--r--examples/dialogs/configdialog/configdialog.qrc7
-rw-r--r--examples/dialogs/configdialog/images/config.pngbin0 -> 6758 bytes
-rw-r--r--examples/dialogs/configdialog/images/query.pngbin0 -> 2116 bytes
-rw-r--r--examples/dialogs/configdialog/images/update.pngbin0 -> 7890 bytes
-rw-r--r--examples/dialogs/configdialog/main.cpp52
-rw-r--r--examples/dialogs/configdialog/pages.cpp151
-rw-r--r--examples/dialogs/configdialog/pages.h64
-rw-r--r--examples/dialogs/dialogs.pro19
-rw-r--r--examples/dialogs/extension/extension.pro11
-rw-r--r--examples/dialogs/extension/finddialog.cpp112
-rw-r--r--examples/dialogs/extension/finddialog.h78
-rw-r--r--examples/dialogs/extension/main.cpp50
-rw-r--r--examples/dialogs/findfiles/findfiles.pro11
-rw-r--r--examples/dialogs/findfiles/main.cpp51
-rw-r--r--examples/dialogs/findfiles/window.cpp249
-rw-r--r--examples/dialogs/findfiles/window.h90
-rw-r--r--examples/dialogs/licensewizard/images/logo.pngbin0 -> 1810 bytes
-rw-r--r--examples/dialogs/licensewizard/images/watermark.pngbin0 -> 34998 bytes
-rw-r--r--examples/dialogs/licensewizard/licensewizard.cpp359
-rw-r--r--examples/dialogs/licensewizard/licensewizard.h163
-rw-r--r--examples/dialogs/licensewizard/licensewizard.pro12
-rw-r--r--examples/dialogs/licensewizard/licensewizard.qrc6
-rw-r--r--examples/dialogs/licensewizard/main.cpp63
-rw-r--r--examples/dialogs/sipdialog/dialog.cpp122
-rw-r--r--examples/dialogs/sipdialog/dialog.h63
-rw-r--r--examples/dialogs/sipdialog/main.cpp52
-rw-r--r--examples/dialogs/sipdialog/sipdialog.pro14
-rw-r--r--examples/dialogs/standarddialogs/dialog.cpp389
-rw-r--r--examples/dialogs/standarddialogs/dialog.h98
-rw-r--r--examples/dialogs/standarddialogs/main.cpp60
-rw-r--r--examples/dialogs/standarddialogs/standarddialogs.pro13
-rw-r--r--examples/dialogs/tabdialog/main.cpp57
-rw-r--r--examples/dialogs/tabdialog/tabdialog.cpp195
-rw-r--r--examples/dialogs/tabdialog/tabdialog.h99
-rw-r--r--examples/dialogs/tabdialog/tabdialog.pro12
-rw-r--r--examples/dialogs/trivialwizard/trivialwizard.cpp135
-rw-r--r--examples/dialogs/trivialwizard/trivialwizard.pro9
-rw-r--r--examples/draganddrop/README40
-rw-r--r--examples/draganddrop/draganddrop.pro15
-rw-r--r--examples/draganddrop/draggableicons/draggableicons.pro15
-rw-r--r--examples/draganddrop/draggableicons/draggableicons.qrc7
-rw-r--r--examples/draganddrop/draggableicons/dragwidget.cpp168
-rw-r--r--examples/draganddrop/draggableicons/dragwidget.h65
-rw-r--r--examples/draganddrop/draggableicons/images/boat.pngbin0 -> 2772 bytes
-rw-r--r--examples/draganddrop/draggableicons/images/car.pngbin0 -> 2963 bytes
-rw-r--r--examples/draganddrop/draggableicons/images/house.pngbin0 -> 3292 bytes
-rw-r--r--examples/draganddrop/draggableicons/main.cpp61
-rw-r--r--examples/draganddrop/draggabletext/draggabletext.pro17
-rw-r--r--examples/draganddrop/draggabletext/draggabletext.qrc5
-rw-r--r--examples/draganddrop/draggabletext/draglabel.cpp51
-rw-r--r--examples/draganddrop/draggabletext/draglabel.h58
-rw-r--r--examples/draganddrop/draggabletext/dragwidget.cpp163
-rw-r--r--examples/draganddrop/draggabletext/dragwidget.h62
-rw-r--r--examples/draganddrop/draggabletext/main.cpp52
-rw-r--r--examples/draganddrop/draggabletext/words.txt41
-rw-r--r--examples/draganddrop/dropsite/droparea.cpp126
-rw-r--r--examples/draganddrop/dropsite/droparea.h77
-rw-r--r--examples/draganddrop/dropsite/dropsite.pro13
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.cpp143
-rw-r--r--examples/draganddrop/dropsite/dropsitewindow.h77
-rw-r--r--examples/draganddrop/dropsite/main.cpp53
-rw-r--r--examples/draganddrop/fridgemagnets/draglabel.cpp89
-rw-r--r--examples/draganddrop/fridgemagnets/draglabel.h64
-rw-r--r--examples/draganddrop/fridgemagnets/dragwidget.cpp214
-rw-r--r--examples/draganddrop/fridgemagnets/dragwidget.h65
-rw-r--r--examples/draganddrop/fridgemagnets/fridgemagnets.pro19
-rw-r--r--examples/draganddrop/fridgemagnets/fridgemagnets.qrc5
-rw-r--r--examples/draganddrop/fridgemagnets/main.cpp60
-rw-r--r--examples/draganddrop/fridgemagnets/words.txt48
-rw-r--r--examples/draganddrop/puzzle/example.jpgbin0 -> 42654 bytes
-rw-r--r--examples/draganddrop/puzzle/main.cpp54
-rw-r--r--examples/draganddrop/puzzle/mainwindow.cpp150
-rw-r--r--examples/draganddrop/puzzle/mainwindow.h76
-rw-r--r--examples/draganddrop/puzzle/pieceslist.cpp121
-rw-r--r--examples/draganddrop/puzzle/pieceslist.h61
-rw-r--r--examples/draganddrop/puzzle/puzzle.pro29
-rw-r--r--examples/draganddrop/puzzle/puzzle.qrc5
-rw-r--r--examples/draganddrop/puzzle/puzzlewidget.cpp204
-rw-r--r--examples/draganddrop/puzzle/puzzlewidget.h85
-rw-r--r--examples/effects/blurpicker/blureffect.cpp68
-rw-r--r--examples/effects/blurpicker/blureffect.h66
-rw-r--r--examples/effects/blurpicker/blurpicker.cpp138
-rw-r--r--examples/effects/blurpicker/blurpicker.h73
-rw-r--r--examples/effects/blurpicker/blurpicker.pro9
-rw-r--r--examples/effects/blurpicker/blurpicker.qrc14
-rw-r--r--examples/effects/blurpicker/images/README.txt5
-rw-r--r--examples/effects/blurpicker/images/accessories-calculator.pngbin0 -> 3760 bytes
-rw-r--r--examples/effects/blurpicker/images/accessories-text-editor.pngbin0 -> 4746 bytes
-rw-r--r--examples/effects/blurpicker/images/background.jpgbin0 -> 16259 bytes
-rw-r--r--examples/effects/blurpicker/images/help-browser.pngbin0 -> 5392 bytes
-rw-r--r--examples/effects/blurpicker/images/internet-group-chat.pngbin0 -> 2809 bytes
-rw-r--r--examples/effects/blurpicker/images/internet-mail.pngbin0 -> 3899 bytes
-rw-r--r--examples/effects/blurpicker/images/internet-web-browser.pngbin0 -> 6376 bytes
-rw-r--r--examples/effects/blurpicker/images/office-calendar.pngbin0 -> 4010 bytes
-rw-r--r--examples/effects/blurpicker/images/system-users.pngbin0 -> 5353 bytes
-rw-r--r--examples/effects/blurpicker/main.cpp54
-rw-r--r--examples/effects/effects.pro13
-rw-r--r--examples/effects/fademessage/README.txt2
-rw-r--r--examples/effects/fademessage/background.jpgbin0 -> 159108 bytes
-rw-r--r--examples/effects/fademessage/fademessage.cpp129
-rw-r--r--examples/effects/fademessage/fademessage.h70
-rw-r--r--examples/effects/fademessage/fademessage.pro16
-rw-r--r--examples/effects/fademessage/fademessage.qrc5
-rw-r--r--examples/effects/fademessage/main.cpp55
-rw-r--r--examples/effects/lighting/lighting.cpp136
-rw-r--r--examples/effects/lighting/lighting.h67
-rw-r--r--examples/effects/lighting/lighting.pro8
-rw-r--r--examples/effects/lighting/main.cpp54
-rw-r--r--examples/examples.pro77
-rw-r--r--examples/gestures/gestures.pro10
-rw-r--r--examples/gestures/imagegestures/imagegestures.pro21
-rw-r--r--examples/gestures/imagegestures/imagewidget.cpp267
-rw-r--r--examples/gestures/imagegestures/imagewidget.h100
-rw-r--r--examples/gestures/imagegestures/main.cpp58
-rw-r--r--examples/gestures/imagegestures/mainwidget.cpp55
-rw-r--r--examples/gestures/imagegestures/mainwidget.h64
-rw-r--r--examples/graphicsview/README40
-rw-r--r--examples/graphicsview/anchorlayout/anchorlayout.pro9
-rw-r--r--examples/graphicsview/anchorlayout/main.cpp128
-rw-r--r--examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro17
-rw-r--r--examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc5
-rw-r--r--examples/graphicsview/basicgraphicslayouts/images/block.pngbin0 -> 2146 bytes
-rw-r--r--examples/graphicsview/basicgraphicslayouts/layoutitem.cpp130
-rw-r--r--examples/graphicsview/basicgraphicslayouts/layoutitem.h65
-rw-r--r--examples/graphicsview/basicgraphicslayouts/main.cpp58
-rw-r--r--examples/graphicsview/basicgraphicslayouts/window.cpp90
-rw-r--r--examples/graphicsview/basicgraphicslayouts/window.h57
-rw-r--r--examples/graphicsview/collidingmice/collidingmice.pro19
-rw-r--r--examples/graphicsview/collidingmice/images/cheese.jpgbin0 -> 3029 bytes
-rw-r--r--examples/graphicsview/collidingmice/main.cpp91
-rw-r--r--examples/graphicsview/collidingmice/mice.qrc5
-rw-r--r--examples/graphicsview/collidingmice/mouse.cpp200
-rw-r--r--examples/graphicsview/collidingmice/mouse.h68
-rw-r--r--examples/graphicsview/diagramscene/arrow.cpp146
-rw-r--r--examples/graphicsview/diagramscene/arrow.h91
-rw-r--r--examples/graphicsview/diagramscene/diagramitem.cpp152
-rw-r--r--examples/graphicsview/diagramscene/diagramitem.h96
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.cpp240
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.h112
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.pro22
-rw-r--r--examples/graphicsview/diagramscene/diagramscene.qrc20
-rw-r--r--examples/graphicsview/diagramscene/diagramtextitem.cpp81
-rw-r--r--examples/graphicsview/diagramscene/diagramtextitem.h78
-rw-r--r--examples/graphicsview/diagramscene/images/background1.pngbin0 -> 112 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/background2.pngbin0 -> 114 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/background3.pngbin0 -> 116 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/background4.pngbin0 -> 96 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/bold.pngbin0 -> 274 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/bringtofront.pngbin0 -> 293 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/delete.pngbin0 -> 831 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/floodfill.pngbin0 -> 282 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/italic.pngbin0 -> 247 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/linecolor.pngbin0 -> 145 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/linepointer.pngbin0 -> 141 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/pointer.pngbin0 -> 173 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/sendtoback.pngbin0 -> 318 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/textpointer.pngbin0 -> 753 bytes
-rw-r--r--examples/graphicsview/diagramscene/images/underline.pngbin0 -> 250 bytes
-rw-r--r--examples/graphicsview/diagramscene/main.cpp55
-rw-r--r--examples/graphicsview/diagramscene/mainwindow.cpp662
-rw-r--r--examples/graphicsview/diagramscene/mainwindow.h150
-rw-r--r--examples/graphicsview/dragdroprobot/coloritem.cpp142
-rw-r--r--examples/graphicsview/dragdroprobot/coloritem.h65
-rw-r--r--examples/graphicsview/dragdroprobot/dragdroprobot.pro20
-rw-r--r--examples/graphicsview/dragdroprobot/images/head.pngbin0 -> 14972 bytes
-rw-r--r--examples/graphicsview/dragdroprobot/main.cpp81
-rw-r--r--examples/graphicsview/dragdroprobot/robot.cpp307
-rw-r--r--examples/graphicsview/dragdroprobot/robot.h118
-rw-r--r--examples/graphicsview/dragdroprobot/robot.qrc5
-rw-r--r--examples/graphicsview/elasticnodes/edge.cpp149
-rw-r--r--examples/graphicsview/elasticnodes/edge.h75
-rw-r--r--examples/graphicsview/elasticnodes/elasticnodes.pro23
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.cpp235
-rw-r--r--examples/graphicsview/elasticnodes/graphwidget.h72
-rw-r--r--examples/graphicsview/elasticnodes/main.cpp53
-rw-r--r--examples/graphicsview/elasticnodes/node.cpp211
-rw-r--r--examples/graphicsview/elasticnodes/node.h85
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.cpp213
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.h76
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.pro10
-rw-r--r--examples/graphicsview/flowlayout/main.cpp55
-rw-r--r--examples/graphicsview/flowlayout/window.cpp62
-rw-r--r--examples/graphicsview/flowlayout/window.h47
-rw-r--r--examples/graphicsview/graphicsview.pro25
-rw-r--r--examples/graphicsview/padnavigator/flippablepad.cpp98
-rw-r--r--examples/graphicsview/padnavigator/flippablepad.h63
-rw-r--r--examples/graphicsview/padnavigator/form.ui208
-rw-r--r--examples/graphicsview/padnavigator/images/artsfftscope.pngbin0 -> 1291 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/blue_angle_swirl.jpgbin0 -> 11826 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/kontact_contacts.pngbin0 -> 4382 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/kontact_journal.pngbin0 -> 3261 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/kontact_mail.pngbin0 -> 3202 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/kontact_notes.pngbin0 -> 3893 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/kopeteavailable.pngbin0 -> 2380 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/metacontact_online.pngbin0 -> 2545 bytes
-rw-r--r--examples/graphicsview/padnavigator/images/minitools.pngbin0 -> 2087 bytes
-rw-r--r--examples/graphicsview/padnavigator/main.cpp56
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.cpp306
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.h70
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.pro32
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.qrc13
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.cpp113
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.h75
-rw-r--r--examples/graphicsview/padnavigator/splashitem.cpp83
-rw-r--r--examples/graphicsview/padnavigator/splashitem.h61
-rw-r--r--examples/graphicsview/simpleanchorlayout/main.cpp133
-rw-r--r--examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro9
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/5days.jpgbin0 -> 5748 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/details.jpgbin0 -> 5323 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/place.jpgbin0 -> 62438 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/tabbar.jpgbin0 -> 849 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/title.jpgbin0 -> 3472 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/images/weather-few-clouds.pngbin0 -> 18976 bytes
-rw-r--r--examples/graphicsview/weatheranchorlayout/main.cpp259
-rw-r--r--examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro14
-rw-r--r--examples/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc10
-rw-r--r--examples/ipc/README35
-rw-r--r--examples/ipc/ipc.pro11
-rw-r--r--examples/ipc/localfortuneclient/client.cpp152
-rw-r--r--examples/ipc/localfortuneclient/client.h81
-rw-r--r--examples/ipc/localfortuneclient/localfortuneclient.pro14
-rw-r--r--examples/ipc/localfortuneclient/main.cpp51
-rw-r--r--examples/ipc/localfortuneserver/localfortuneserver.pro14
-rw-r--r--examples/ipc/localfortuneserver/main.cpp55
-rw-r--r--examples/ipc/localfortuneserver/server.cpp110
-rw-r--r--examples/ipc/localfortuneserver/server.h69
-rw-r--r--examples/ipc/sharedmemory/dialog.cpp188
-rw-r--r--examples/ipc/sharedmemory/dialog.h70
-rw-r--r--examples/ipc/sharedmemory/dialog.ui47
-rw-r--r--examples/ipc/sharedmemory/image.pngbin0 -> 10199 bytes
-rw-r--r--examples/ipc/sharedmemory/main.cpp53
-rw-r--r--examples/ipc/sharedmemory/qt.pngbin0 -> 2383 bytes
-rw-r--r--examples/ipc/sharedmemory/sharedmemory.pro15
-rw-r--r--examples/itemviews/README39
-rw-r--r--examples/itemviews/addressbook/adddialog.cpp82
-rw-r--r--examples/itemviews/addressbook/adddialog.h71
-rw-r--r--examples/itemviews/addressbook/addressbook.pro22
-rw-r--r--examples/itemviews/addressbook/addresswidget.cpp237
-rw-r--r--examples/itemviews/addressbook/addresswidget.h82
-rw-r--r--examples/itemviews/addressbook/main.cpp52
-rw-r--r--examples/itemviews/addressbook/mainwindow.cpp137
-rw-r--r--examples/itemviews/addressbook/mainwindow.h75
-rw-r--r--examples/itemviews/addressbook/newaddresstab.cpp77
-rw-r--r--examples/itemviews/addressbook/newaddresstab.h74
-rw-r--r--examples/itemviews/addressbook/tablemodel.cpp184
-rw-r--r--examples/itemviews/addressbook/tablemodel.h72
-rw-r--r--examples/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro12
-rw-r--r--examples/itemviews/basicsortfiltermodel/main.cpp93
-rw-r--r--examples/itemviews/basicsortfiltermodel/window.cpp156
-rw-r--r--examples/itemviews/basicsortfiltermodel/window.h88
-rw-r--r--examples/itemviews/chart/chart.pro20
-rw-r--r--examples/itemviews/chart/chart.qrc5
-rw-r--r--examples/itemviews/chart/main.cpp53
-rw-r--r--examples/itemviews/chart/mainwindow.cpp172
-rw-r--r--examples/itemviews/chart/mainwindow.h72
-rw-r--r--examples/itemviews/chart/mydata.cht8
-rw-r--r--examples/itemviews/chart/pieview.cpp561
-rw-r--r--examples/itemviews/chart/pieview.h114
-rw-r--r--examples/itemviews/chart/qtdata.cht14
-rw-r--r--examples/itemviews/coloreditorfactory/coloreditorfactory.pro13
-rw-r--r--examples/itemviews/coloreditorfactory/colorlisteditor.cpp76
-rw-r--r--examples/itemviews/coloreditorfactory/colorlisteditor.h69
-rw-r--r--examples/itemviews/coloreditorfactory/main.cpp53
-rw-r--r--examples/itemviews/coloreditorfactory/window.cpp94
-rw-r--r--examples/itemviews/coloreditorfactory/window.h57
-rw-r--r--examples/itemviews/combowidgetmapper/combowidgetmapper.pro9
-rw-r--r--examples/itemviews/combowidgetmapper/main.cpp51
-rw-r--r--examples/itemviews/combowidgetmapper/window.cpp136
-rw-r--r--examples/itemviews/combowidgetmapper/window.h86
-rw-r--r--examples/itemviews/customsortfiltermodel/customsortfiltermodel.pro14
-rw-r--r--examples/itemviews/customsortfiltermodel/main.cpp95
-rw-r--r--examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp115
-rw-r--r--examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.h73
-rw-r--r--examples/itemviews/customsortfiltermodel/window.cpp167
-rw-r--r--examples/itemviews/customsortfiltermodel/window.h90
-rw-r--r--examples/itemviews/dirview/dirview.pro9
-rw-r--r--examples/itemviews/dirview/main.cpp62
-rw-r--r--examples/itemviews/editabletreemodel/default.txt40
-rw-r--r--examples/itemviews/editabletreemodel/editabletreemodel.pro18
-rw-r--r--examples/itemviews/editabletreemodel/editabletreemodel.qrc5
-rw-r--r--examples/itemviews/editabletreemodel/main.cpp53
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.cpp180
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.h71
-rw-r--r--examples/itemviews/editabletreemodel/mainwindow.ui128
-rw-r--r--examples/itemviews/editabletreemodel/treeitem.cpp179
-rw-r--r--examples/itemviews/editabletreemodel/treeitem.h74
-rw-r--r--examples/itemviews/editabletreemodel/treemodel.cpp288
-rw-r--r--examples/itemviews/editabletreemodel/treemodel.h97
-rw-r--r--examples/itemviews/fetchmore/fetchmore.pro12
-rw-r--r--examples/itemviews/fetchmore/filelistmodel.cpp115
-rw-r--r--examples/itemviews/fetchmore/filelistmodel.h75
-rw-r--r--examples/itemviews/fetchmore/main.cpp50
-rw-r--r--examples/itemviews/fetchmore/window.cpp81
-rw-r--r--examples/itemviews/fetchmore/window.h64
-rw-r--r--examples/itemviews/frozencolumn/freezetablewidget.cpp165
-rw-r--r--examples/itemviews/frozencolumn/freezetablewidget.h72
-rw-r--r--examples/itemviews/frozencolumn/frozencolumn.pro9
-rw-r--r--examples/itemviews/frozencolumn/grades.qrc5
-rw-r--r--examples/itemviews/frozencolumn/grades.txt36
-rw-r--r--examples/itemviews/frozencolumn/main.cpp88
-rw-r--r--examples/itemviews/itemviews.pro29
-rw-r--r--examples/itemviews/pixelator/imagemodel.cpp91
-rw-r--r--examples/itemviews/pixelator/imagemodel.h68
-rw-r--r--examples/itemviews/pixelator/images.qrc5
-rw-r--r--examples/itemviews/pixelator/images/qt.pngbin0 -> 656 bytes
-rw-r--r--examples/itemviews/pixelator/main.cpp54
-rw-r--r--examples/itemviews/pixelator/mainwindow.cpp244
-rw-r--r--examples/itemviews/pixelator/mainwindow.h74
-rw-r--r--examples/itemviews/pixelator/pixelator.pro16
-rw-r--r--examples/itemviews/pixelator/pixeldelegate.cpp107
-rw-r--r--examples/itemviews/pixelator/pixeldelegate.h79
-rw-r--r--examples/itemviews/puzzle/example.jpgbin0 -> 42654 bytes
-rw-r--r--examples/itemviews/puzzle/main.cpp54
-rw-r--r--examples/itemviews/puzzle/mainwindow.cpp149
-rw-r--r--examples/itemviews/puzzle/mainwindow.h77
-rw-r--r--examples/itemviews/puzzle/piecesmodel.cpp203
-rw-r--r--examples/itemviews/puzzle/piecesmodel.h80
-rw-r--r--examples/itemviews/puzzle/puzzle.pro21
-rw-r--r--examples/itemviews/puzzle/puzzle.qrc5
-rw-r--r--examples/itemviews/puzzle/puzzlewidget.cpp204
-rw-r--r--examples/itemviews/puzzle/puzzlewidget.h85
-rw-r--r--examples/itemviews/simpledommodel/domitem.cpp101
-rw-r--r--examples/itemviews/simpledommodel/domitem.h66
-rw-r--r--examples/itemviews/simpledommodel/dommodel.cpp189
-rw-r--r--examples/itemviews/simpledommodel/dommodel.h76
-rw-r--r--examples/itemviews/simpledommodel/main.cpp52
-rw-r--r--examples/itemviews/simpledommodel/mainwindow.cpp84
-rw-r--r--examples/itemviews/simpledommodel/mainwindow.h70
-rw-r--r--examples/itemviews/simpledommodel/simpledommodel.pro17
-rw-r--r--examples/itemviews/simpletreemodel/default.txt40
-rw-r--r--examples/itemviews/simpletreemodel/main.cpp61
-rw-r--r--examples/itemviews/simpletreemodel/simpletreemodel.pro15
-rw-r--r--examples/itemviews/simpletreemodel/simpletreemodel.qrc5
-rw-r--r--examples/itemviews/simpletreemodel/treeitem.cpp116
-rw-r--r--examples/itemviews/simpletreemodel/treeitem.h70
-rw-r--r--examples/itemviews/simpletreemodel/treemodel.cpp218
-rw-r--r--examples/itemviews/simpletreemodel/treemodel.h76
-rw-r--r--examples/itemviews/simplewidgetmapper/main.cpp51
-rw-r--r--examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro11
-rw-r--r--examples/itemviews/simplewidgetmapper/window.cpp133
-rw-r--r--examples/itemviews/simplewidgetmapper/window.h84
-rw-r--r--examples/itemviews/spinboxdelegate/delegate.cpp102
-rw-r--r--examples/itemviews/spinboxdelegate/delegate.h70
-rw-r--r--examples/itemviews/spinboxdelegate/main.cpp86
-rw-r--r--examples/itemviews/spinboxdelegate/spinboxdelegate.pro11
-rw-r--r--examples/itemviews/stardelegate/main.cpp107
-rw-r--r--examples/itemviews/stardelegate/stardelegate.cpp129
-rw-r--r--examples/itemviews/stardelegate/stardelegate.h69
-rw-r--r--examples/itemviews/stardelegate/stardelegate.pro16
-rw-r--r--examples/itemviews/stardelegate/stareditor.cpp98
-rw-r--r--examples/itemviews/stardelegate/stareditor.h77
-rw-r--r--examples/itemviews/stardelegate/starrating.cpp102
-rw-r--r--examples/itemviews/stardelegate/starrating.h76
-rw-r--r--examples/ja_JP/linguist/hellotr/hellotr.pro13
-rw-r--r--examples/ja_JP/linguist/hellotr/main.cpp70
-rw-r--r--examples/layouts/README41
-rw-r--r--examples/layouts/basiclayouts/basiclayouts.pro11
-rw-r--r--examples/layouts/basiclayouts/dialog.cpp149
-rw-r--r--examples/layouts/basiclayouts/dialog.h90
-rw-r--r--examples/layouts/basiclayouts/main.cpp50
-rw-r--r--examples/layouts/borderlayout/borderlayout.cpp213
-rw-r--r--examples/layouts/borderlayout/borderlayout.h88
-rw-r--r--examples/layouts/borderlayout/borderlayout.pro13
-rw-r--r--examples/layouts/borderlayout/main.cpp51
-rw-r--r--examples/layouts/borderlayout/window.cpp68
-rw-r--r--examples/layouts/borderlayout/window.h61
-rw-r--r--examples/layouts/dynamiclayouts/dialog.cpp169
-rw-r--r--examples/layouts/dynamiclayouts/dialog.h90
-rw-r--r--examples/layouts/dynamiclayouts/dynamiclayouts.pro11
-rw-r--r--examples/layouts/dynamiclayouts/main.cpp50
-rw-r--r--examples/layouts/flowlayout/flowlayout.cpp213
-rw-r--r--examples/layouts/flowlayout/flowlayout.h78
-rw-r--r--examples/layouts/flowlayout/flowlayout.pro13
-rw-r--r--examples/layouts/flowlayout/main.cpp51
-rw-r--r--examples/layouts/flowlayout/window.cpp59
-rw-r--r--examples/layouts/flowlayout/window.h59
-rw-r--r--examples/layouts/layouts.pro12
-rw-r--r--examples/linguist/README37
-rw-r--r--examples/linguist/arrowpad/arrowpad.cpp64
-rw-r--r--examples/linguist/arrowpad/arrowpad.h68
-rw-r--r--examples/linguist/arrowpad/arrowpad.pro18
-rw-r--r--examples/linguist/arrowpad/main.cpp63
-rw-r--r--examples/linguist/arrowpad/mainwindow.cpp61
-rw-r--r--examples/linguist/arrowpad/mainwindow.h68
-rw-r--r--examples/linguist/hellotr/hellotr.pro13
-rw-r--r--examples/linguist/hellotr/main.cpp70
-rw-r--r--examples/linguist/linguist.pro11
-rw-r--r--examples/linguist/trollprint/main.cpp60
-rw-r--r--examples/linguist/trollprint/mainwindow.cpp95
-rw-r--r--examples/linguist/trollprint/mainwindow.h74
-rw-r--r--examples/linguist/trollprint/printpanel.cpp85
-rw-r--r--examples/linguist/trollprint/printpanel.h69
-rw-r--r--examples/linguist/trollprint/trollprint.pro14
-rw-r--r--examples/linguist/trollprint/trollprint_pt.ts65
-rw-r--r--examples/mainwindows/README40
-rw-r--r--examples/mainwindows/application/application.pro14
-rw-r--r--examples/mainwindows/application/application.qrc10
-rw-r--r--examples/mainwindows/application/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/mainwindows/application/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/mainwindows/application/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/mainwindows/application/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/mainwindows/application/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/mainwindows/application/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/mainwindows/application/main.cpp57
-rw-r--r--examples/mainwindows/application/mainwindow.cpp392
-rw-r--r--examples/mainwindows/application/mainwindow.h105
-rw-r--r--examples/mainwindows/dockwidgets/dockwidgets.pro12
-rw-r--r--examples/mainwindows/dockwidgets/dockwidgets.qrc8
-rw-r--r--examples/mainwindows/dockwidgets/images/new.pngbin0 -> 977 bytes
-rw-r--r--examples/mainwindows/dockwidgets/images/print.pngbin0 -> 1732 bytes
-rw-r--r--examples/mainwindows/dockwidgets/images/save.pngbin0 -> 1894 bytes
-rw-r--r--examples/mainwindows/dockwidgets/images/undo.pngbin0 -> 1768 bytes
-rw-r--r--examples/mainwindows/dockwidgets/main.cpp52
-rw-r--r--examples/mainwindows/dockwidgets/mainwindow.cpp342
-rw-r--r--examples/mainwindows/dockwidgets/mainwindow.h97
-rw-r--r--examples/mainwindows/mainwindows.pro19
-rw-r--r--examples/mainwindows/mdi/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/mainwindows/mdi/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/mainwindows/mdi/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/mainwindows/mdi/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/mainwindows/mdi/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/mainwindows/mdi/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/mainwindows/mdi/main.cpp53
-rw-r--r--examples/mainwindows/mdi/mainwindow.cpp397
-rw-r--r--examples/mainwindows/mdi/mainwindow.h118
-rw-r--r--examples/mainwindows/mdi/mdi.pro14
-rw-r--r--examples/mainwindows/mdi/mdi.qrc10
-rw-r--r--examples/mainwindows/mdi/mdichild.cpp175
-rw-r--r--examples/mainwindows/mdi/mdichild.h76
-rw-r--r--examples/mainwindows/menus/main.cpp51
-rw-r--r--examples/mainwindows/menus/mainwindow.cpp370
-rw-r--r--examples/mainwindows/menus/mainwindow.h124
-rw-r--r--examples/mainwindows/menus/menus.pro14
-rw-r--r--examples/mainwindows/recentfiles/main.cpp53
-rw-r--r--examples/mainwindows/recentfiles/mainwindow.cpp251
-rw-r--r--examples/mainwindows/recentfiles/mainwindow.h96
-rw-r--r--examples/mainwindows/recentfiles/recentfiles.pro11
-rw-r--r--examples/mainwindows/sdi/images/copy.pngbin0 -> 1338 bytes
-rw-r--r--examples/mainwindows/sdi/images/cut.pngbin0 -> 1323 bytes
-rw-r--r--examples/mainwindows/sdi/images/new.pngbin0 -> 852 bytes
-rw-r--r--examples/mainwindows/sdi/images/open.pngbin0 -> 2073 bytes
-rw-r--r--examples/mainwindows/sdi/images/paste.pngbin0 -> 1645 bytes
-rw-r--r--examples/mainwindows/sdi/images/save.pngbin0 -> 1187 bytes
-rw-r--r--examples/mainwindows/sdi/main.cpp54
-rw-r--r--examples/mainwindows/sdi/mainwindow.cpp372
-rw-r--r--examples/mainwindows/sdi/mainwindow.h110
-rw-r--r--examples/mainwindows/sdi/sdi.pro12
-rw-r--r--examples/mainwindows/sdi/sdi.qrc10
-rw-r--r--examples/network/README40
-rw-r--r--examples/network/bearermonitor/bearermonitor.cpp423
-rw-r--r--examples/network/bearermonitor/bearermonitor.h94
-rw-r--r--examples/network/bearermonitor/bearermonitor.pro26
-rw-r--r--examples/network/bearermonitor/bearermonitor_240_320.ui420
-rw-r--r--examples/network/bearermonitor/bearermonitor_640_480.ui386
-rw-r--r--examples/network/bearermonitor/bearermonitor_maemo.ui369
-rw-r--r--examples/network/bearermonitor/main.cpp59
-rw-r--r--examples/network/bearermonitor/sessionwidget.cpp204
-rw-r--r--examples/network/bearermonitor/sessionwidget.h86
-rw-r--r--examples/network/bearermonitor/sessionwidget.ui307
-rw-r--r--examples/network/bearermonitor/sessionwidget_maemo.ui310
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.cpp168
-rw-r--r--examples/network/blockingfortuneclient/blockingclient.h84
-rw-r--r--examples/network/blockingfortuneclient/blockingfortuneclient.pro14
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.cpp137
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.h73
-rw-r--r--examples/network/blockingfortuneclient/main.cpp51
-rw-r--r--examples/network/broadcastreceiver/broadcastreceiver.pro12
-rw-r--r--examples/network/broadcastreceiver/main.cpp51
-rw-r--r--examples/network/broadcastreceiver/receiver.cpp87
-rw-r--r--examples/network/broadcastreceiver/receiver.h68
-rw-r--r--examples/network/broadcastsender/broadcastsender.pro12
-rw-r--r--examples/network/broadcastsender/main.cpp51
-rw-r--r--examples/network/broadcastsender/sender.cpp91
-rw-r--r--examples/network/broadcastsender/sender.h75
-rw-r--r--examples/network/download/download.pro21
-rw-r--r--examples/network/download/main.cpp192
-rw-r--r--examples/network/downloadmanager/downloadmanager.cpp172
-rw-r--r--examples/network/downloadmanager/downloadmanager.h84
-rw-r--r--examples/network/downloadmanager/downloadmanager.pro22
-rw-r--r--examples/network/downloadmanager/main.cpp67
-rw-r--r--examples/network/downloadmanager/textprogressbar.cpp98
-rw-r--r--examples/network/downloadmanager/textprogressbar.h63
-rw-r--r--examples/network/fortuneclient/client.cpp252
-rw-r--r--examples/network/fortuneclient/client.h89
-rw-r--r--examples/network/fortuneclient/fortuneclient.pro16
-rw-r--r--examples/network/fortuneclient/main.cpp55
-rw-r--r--examples/network/fortuneserver/fortuneserver.pro17
-rw-r--r--examples/network/fortuneserver/main.cpp59
-rw-r--r--examples/network/fortuneserver/server.cpp176
-rw-r--r--examples/network/fortuneserver/server.h74
-rw-r--r--examples/network/googlesuggest/googlesuggest.cpp234
-rw-r--r--examples/network/googlesuggest/googlesuggest.h81
-rw-r--r--examples/network/googlesuggest/googlesuggest.pro9
-rw-r--r--examples/network/googlesuggest/main.cpp51
-rw-r--r--examples/network/googlesuggest/searchbox.cpp72
-rw-r--r--examples/network/googlesuggest/searchbox.h65
-rw-r--r--examples/network/http/authenticationdialog.ui129
-rw-r--r--examples/network/http/http.pro13
-rw-r--r--examples/network/http/httpwindow.cpp266
-rw-r--r--examples/network/http/httpwindow.h100
-rw-r--r--examples/network/http/main.cpp51
-rw-r--r--examples/network/loopback/dialog.cpp190
-rw-r--r--examples/network/loopback/dialog.h89
-rw-r--r--examples/network/loopback/loopback.pro12
-rw-r--r--examples/network/loopback/main.cpp51
-rw-r--r--examples/network/multicastreceiver/main.cpp51
-rw-r--r--examples/network/multicastreceiver/multicastreceiver.pro12
-rw-r--r--examples/network/multicastreceiver/receiver.cpp84
-rw-r--r--examples/network/multicastreceiver/receiver.h70
-rw-r--r--examples/network/multicastsender/main.cpp51
-rw-r--r--examples/network/multicastsender/multicastsender.pro12
-rw-r--r--examples/network/multicastsender/sender.cpp105
-rw-r--r--examples/network/multicastsender/sender.h81
-rw-r--r--examples/network/network-chat/chatdialog.cpp141
-rw-r--r--examples/network/network-chat/chatdialog.h69
-rw-r--r--examples/network/network-chat/chatdialog.ui79
-rw-r--r--examples/network/network-chat/client.cpp139
-rw-r--r--examples/network/network-chat/client.h82
-rw-r--r--examples/network/network-chat/connection.cpp275
-rw-r--r--examples/network/network-chat/connection.h107
-rw-r--r--examples/network/network-chat/main.cpp98
-rw-r--r--examples/network/network-chat/network-chat.pro26
-rw-r--r--examples/network/network-chat/peermanager.cpp172
-rw-r--r--examples/network/network-chat/peermanager.h84
-rw-r--r--examples/network/network-chat/server.cpp57
-rw-r--r--examples/network/network-chat/server.h62
-rw-r--r--examples/network/network.pro41
-rw-r--r--examples/network/qftp/ftp.qrc7
-rw-r--r--examples/network/qftp/ftpwindow.cpp407
-rw-r--r--examples/network/qftp/ftpwindow.h107
-rw-r--r--examples/network/qftp/images/cdtoparent.pngbin0 -> 139 bytes
-rw-r--r--examples/network/qftp/images/dir.pngbin0 -> 154 bytes
-rw-r--r--examples/network/qftp/images/file.pngbin0 -> 129 bytes
-rw-r--r--examples/network/qftp/main.cpp66
-rw-r--r--examples/network/qftp/qftp.pro18
-rw-r--r--examples/network/securesocketclient/certificateinfo.cpp99
-rw-r--r--examples/network/securesocketclient/certificateinfo.h68
-rw-r--r--examples/network/securesocketclient/certificateinfo.ui85
-rw-r--r--examples/network/securesocketclient/encrypted.pngbin0 -> 750 bytes
-rw-r--r--examples/network/securesocketclient/main.cpp62
-rw-r--r--examples/network/securesocketclient/securesocketclient.pro21
-rw-r--r--examples/network/securesocketclient/securesocketclient.qrc5
-rw-r--r--examples/network/securesocketclient/sslclient.cpp219
-rw-r--r--examples/network/securesocketclient/sslclient.h80
-rw-r--r--examples/network/securesocketclient/sslclient.ui190
-rw-r--r--examples/network/securesocketclient/sslerrors.ui110
-rw-r--r--examples/network/threadedfortuneserver/dialog.cpp94
-rw-r--r--examples/network/threadedfortuneserver/dialog.h65
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.cpp68
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.h63
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.cpp76
-rw-r--r--examples/network/threadedfortuneserver/fortunethread.h66
-rw-r--r--examples/network/threadedfortuneserver/main.cpp55
-rw-r--r--examples/network/threadedfortuneserver/threadedfortuneserver.pro16
-rw-r--r--examples/network/torrent/addtorrentdialog.cpp169
-rw-r--r--examples/network/torrent/addtorrentdialog.h73
-rw-r--r--examples/network/torrent/bencodeparser.cpp234
-rw-r--r--examples/network/torrent/bencodeparser.h80
-rw-r--r--examples/network/torrent/connectionmanager.cpp88
-rw-r--r--examples/network/torrent/connectionmanager.h65
-rw-r--r--examples/network/torrent/filemanager.cpp446
-rw-r--r--examples/network/torrent/filemanager.h143
-rw-r--r--examples/network/torrent/forms/addtorrentform.ui266
-rw-r--r--examples/network/torrent/icons.qrc12
-rw-r--r--examples/network/torrent/icons/1downarrow.pngbin0 -> 895 bytes
-rw-r--r--examples/network/torrent/icons/1uparrow.pngbin0 -> 822 bytes
-rw-r--r--examples/network/torrent/icons/bottom.pngbin0 -> 1632 bytes
-rw-r--r--examples/network/torrent/icons/edit_add.pngbin0 -> 394 bytes
-rw-r--r--examples/network/torrent/icons/edit_remove.pngbin0 -> 368 bytes
-rw-r--r--examples/network/torrent/icons/exit.pngbin0 -> 1426 bytes
-rw-r--r--examples/network/torrent/icons/peertopeer.pngbin0 -> 10072 bytes
-rw-r--r--examples/network/torrent/icons/player_pause.pngbin0 -> 690 bytes
-rw-r--r--examples/network/torrent/icons/player_play.pngbin0 -> 900 bytes
-rw-r--r--examples/network/torrent/icons/player_stop.pngbin0 -> 627 bytes
-rw-r--r--examples/network/torrent/icons/stop.pngbin0 -> 1252 bytes
-rw-r--r--examples/network/torrent/main.cpp57
-rw-r--r--examples/network/torrent/mainwindow.cpp712
-rw-r--r--examples/network/torrent/mainwindow.h131
-rw-r--r--examples/network/torrent/metainfo.cpp217
-rw-r--r--examples/network/torrent/metainfo.h121
-rw-r--r--examples/network/torrent/peerwireclient.cpp664
-rw-r--r--examples/network/torrent/peerwireclient.h209
-rw-r--r--examples/network/torrent/ratecontroller.cpp155
-rw-r--r--examples/network/torrent/ratecontroller.h79
-rw-r--r--examples/network/torrent/torrent.pro39
-rw-r--r--examples/network/torrent/torrentclient.cpp1528
-rw-r--r--examples/network/torrent/torrentclient.h204
-rw-r--r--examples/network/torrent/torrentserver.cpp103
-rw-r--r--examples/network/torrent/torrentserver.h71
-rw-r--r--examples/network/torrent/trackerclient.cpp236
-rw-r--r--examples/network/torrent/trackerclient.h103
-rw-r--r--examples/opengl/2dpainting/2dpainting.pro19
-rw-r--r--examples/opengl/2dpainting/glwidget.cpp72
-rw-r--r--examples/opengl/2dpainting/glwidget.h72
-rw-r--r--examples/opengl/2dpainting/helper.cpp90
-rw-r--r--examples/opengl/2dpainting/helper.h71
-rw-r--r--examples/opengl/2dpainting/main.cpp50
-rw-r--r--examples/opengl/2dpainting/widget.cpp72
-rw-r--r--examples/opengl/2dpainting/widget.h71
-rw-r--r--examples/opengl/2dpainting/window.cpp71
-rw-r--r--examples/opengl/2dpainting/window.h66
-rw-r--r--examples/opengl/README41
-rw-r--r--examples/opengl/framebufferobject2/cubelogo.pngbin0 -> 5920 bytes
-rw-r--r--examples/opengl/framebufferobject2/framebufferobject2.pro13
-rw-r--r--examples/opengl/framebufferobject2/framebufferobject2.qrc5
-rw-r--r--examples/opengl/framebufferobject2/glwidget.cpp248
-rw-r--r--examples/opengl/framebufferobject2/glwidget.h65
-rw-r--r--examples/opengl/framebufferobject2/main.cpp61
-rw-r--r--examples/opengl/grabber/glwidget.cpp283
-rw-r--r--examples/opengl/grabber/glwidget.h97
-rw-r--r--examples/opengl/grabber/grabber.pro14
-rw-r--r--examples/opengl/grabber/main.cpp51
-rw-r--r--examples/opengl/grabber/mainwindow.cpp206
-rw-r--r--examples/opengl/grabber/mainwindow.h94
-rw-r--r--examples/opengl/hellogl/glwidget.cpp199
-rw-r--r--examples/opengl/hellogl/glwidget.h94
-rw-r--r--examples/opengl/hellogl/hellogl.pro19
-rw-r--r--examples/opengl/hellogl/main.cpp59
-rw-r--r--examples/opengl/hellogl/window.cpp97
-rw-r--r--examples/opengl/hellogl/window.h72
-rw-r--r--examples/opengl/hellogl_es/bubble.cpp139
-rw-r--r--examples/opengl/hellogl_es/bubble.h76
-rw-r--r--examples/opengl/hellogl_es/glwidget.cpp455
-rw-r--r--examples/opengl/hellogl_es/glwidget.h85
-rw-r--r--examples/opengl/hellogl_es/hellogl_es.pro27
-rw-r--r--examples/opengl/hellogl_es/main.cpp52
-rw-r--r--examples/opengl/hellogl_es/mainwindow.cpp107
-rw-r--r--examples/opengl/hellogl_es/mainwindow.h59
-rw-r--r--examples/opengl/hellogl_es/qt.pngbin0 -> 5174 bytes
-rw-r--r--examples/opengl/hellogl_es/texture.qrc5
-rw-r--r--examples/opengl/hellogl_es2/bubble.cpp139
-rw-r--r--examples/opengl/hellogl_es2/bubble.h76
-rw-r--r--examples/opengl/hellogl_es2/glwidget.cpp463
-rw-r--r--examples/opengl/hellogl_es2/glwidget.h94
-rw-r--r--examples/opengl/hellogl_es2/hellogl_es2.pro27
-rw-r--r--examples/opengl/hellogl_es2/main.cpp52
-rw-r--r--examples/opengl/hellogl_es2/mainwindow.cpp107
-rw-r--r--examples/opengl/hellogl_es2/mainwindow.h59
-rw-r--r--examples/opengl/hellogl_es2/qt.pngbin0 -> 5174 bytes
-rw-r--r--examples/opengl/hellogl_es2/texture.qrc5
-rw-r--r--examples/opengl/opengl.pro35
-rw-r--r--examples/opengl/overpainting/bubble.cpp112
-rw-r--r--examples/opengl/overpainting/bubble.h75
-rw-r--r--examples/opengl/overpainting/glwidget.cpp283
-rw-r--r--examples/opengl/overpainting/glwidget.h111
-rw-r--r--examples/opengl/overpainting/main.cpp50
-rw-r--r--examples/opengl/overpainting/overpainting.pro23
-rw-r--r--examples/opengl/pbuffers/cube.cpp348
-rw-r--r--examples/opengl/pbuffers/cube.h149
-rw-r--r--examples/opengl/pbuffers/cubelogo.pngbin0 -> 5920 bytes
-rw-r--r--examples/opengl/pbuffers/glwidget.cpp246
-rw-r--r--examples/opengl/pbuffers/glwidget.h89
-rw-r--r--examples/opengl/pbuffers/main.cpp63
-rw-r--r--examples/opengl/pbuffers/pbuffers.pro19
-rw-r--r--examples/opengl/pbuffers/pbuffers.qrc5
-rw-r--r--examples/opengl/pbuffers2/bubbles.svg215
-rw-r--r--examples/opengl/pbuffers2/designer.pngbin0 -> 2810 bytes
-rw-r--r--examples/opengl/pbuffers2/glwidget.cpp327
-rw-r--r--examples/opengl/pbuffers2/glwidget.h84
-rw-r--r--examples/opengl/pbuffers2/main.cpp61
-rw-r--r--examples/opengl/pbuffers2/pbuffers2.pro23
-rw-r--r--examples/opengl/pbuffers2/pbuffers2.qrc6
-rw-r--r--examples/opengl/samplebuffers/glwidget.cpp164
-rw-r--r--examples/opengl/samplebuffers/glwidget.h61
-rw-r--r--examples/opengl/samplebuffers/main.cpp71
-rw-r--r--examples/opengl/samplebuffers/samplebuffers.pro12
-rw-r--r--examples/opengl/shared/qtlogo.cpp411
-rw-r--r--examples/opengl/shared/qtlogo.h66
-rw-r--r--examples/opengl/textures/glwidget.cpp245
-rw-r--r--examples/opengl/textures/glwidget.h89
-rw-r--r--examples/opengl/textures/images/side1.pngbin0 -> 935 bytes
-rw-r--r--examples/opengl/textures/images/side2.pngbin0 -> 1622 bytes
-rw-r--r--examples/opengl/textures/images/side3.pngbin0 -> 2117 bytes
-rw-r--r--examples/opengl/textures/images/side4.pngbin0 -> 1222 bytes
-rw-r--r--examples/opengl/textures/images/side5.pngbin0 -> 1806 bytes
-rw-r--r--examples/opengl/textures/images/side6.pngbin0 -> 2215 bytes
-rw-r--r--examples/opengl/textures/main.cpp53
-rw-r--r--examples/opengl/textures/textures.pro15
-rw-r--r--examples/opengl/textures/textures.qrc10
-rw-r--r--examples/opengl/textures/window.cpp86
-rw-r--r--examples/opengl/textures/window.h66
-rw-r--r--examples/openvg/README40
-rw-r--r--examples/openvg/openvg.pro8
-rw-r--r--examples/openvg/star/main.cpp53
-rw-r--r--examples/openvg/star/star.pro7
-rw-r--r--examples/openvg/star/starwidget.cpp115
-rw-r--r--examples/openvg/star/starwidget.h65
-rw-r--r--examples/painting/README42
-rw-r--r--examples/painting/basicdrawing/basicdrawing.pro17
-rw-r--r--examples/painting/basicdrawing/basicdrawing.qrc6
-rw-r--r--examples/painting/basicdrawing/images/brick.pngbin0 -> 767 bytes
-rw-r--r--examples/painting/basicdrawing/images/qt-logo.pngbin0 -> 3696 bytes
-rw-r--r--examples/painting/basicdrawing/main.cpp53
-rw-r--r--examples/painting/basicdrawing/renderarea.cpp207
-rw-r--r--examples/painting/basicdrawing/renderarea.h83
-rw-r--r--examples/painting/basicdrawing/window.cpp261
-rw-r--r--examples/painting/basicdrawing/window.h87
-rw-r--r--examples/painting/concentriccircles/circlewidget.cpp124
-rw-r--r--examples/painting/concentriccircles/circlewidget.h73
-rw-r--r--examples/painting/concentriccircles/concentriccircles.pro16
-rw-r--r--examples/painting/concentriccircles/main.cpp51
-rw-r--r--examples/painting/concentriccircles/window.cpp93
-rw-r--r--examples/painting/concentriccircles/window.h70
-rw-r--r--examples/painting/fontsampler/fontsampler.pro12
-rw-r--r--examples/painting/fontsampler/main.cpp51
-rw-r--r--examples/painting/fontsampler/mainwindow.cpp372
-rw-r--r--examples/painting/fontsampler/mainwindow.h82
-rw-r--r--examples/painting/fontsampler/mainwindowbase.ui140
-rw-r--r--examples/painting/imagecomposition/imagecomposer.cpp208
-rw-r--r--examples/painting/imagecomposition/imagecomposer.h87
-rw-r--r--examples/painting/imagecomposition/imagecomposition.pro15
-rw-r--r--examples/painting/imagecomposition/imagecomposition.qrc6
-rw-r--r--examples/painting/imagecomposition/images/background.pngbin0 -> 18579 bytes
-rw-r--r--examples/painting/imagecomposition/images/blackrectangle.pngbin0 -> 90 bytes
-rw-r--r--examples/painting/imagecomposition/images/butterfly.pngbin0 -> 36868 bytes
-rw-r--r--examples/painting/imagecomposition/images/checker.pngbin0 -> 10384 bytes
-rw-r--r--examples/painting/imagecomposition/main.cpp55
-rw-r--r--examples/painting/painterpaths/main.cpp51
-rw-r--r--examples/painting/painterpaths/painterpaths.pro17
-rw-r--r--examples/painting/painterpaths/renderarea.cpp130
-rw-r--r--examples/painting/painterpaths/renderarea.h80
-rw-r--r--examples/painting/painterpaths/window.cpp288
-rw-r--r--examples/painting/painterpaths/window.h92
-rw-r--r--examples/painting/painting.pro18
-rw-r--r--examples/painting/transformations/main.cpp51
-rw-r--r--examples/painting/transformations/renderarea.cpp172
-rw-r--r--examples/painting/transformations/renderarea.h90
-rw-r--r--examples/painting/transformations/transformations.pro16
-rw-r--r--examples/painting/transformations/window.cpp180
-rw-r--r--examples/painting/transformations/window.h80
-rw-r--r--examples/qmake/precompile/main.cpp60
-rw-r--r--examples/qmake/precompile/mydialog.cpp47
-rw-r--r--examples/qmake/precompile/mydialog.h54
-rw-r--r--examples/qmake/precompile/mydialog.ui47
-rw-r--r--examples/qmake/precompile/myobject.cpp57
-rw-r--r--examples/qmake/precompile/myobject.h55
-rw-r--r--examples/qmake/precompile/precompile.pro22
-rw-r--r--examples/qmake/precompile/stable.h52
-rw-r--r--examples/qmake/precompile/util.cpp49
-rw-r--r--examples/qmake/tutorial/hello.cpp49
-rw-r--r--examples/qmake/tutorial/hello.h47
-rw-r--r--examples/qmake/tutorial/hellounix.cpp42
-rw-r--r--examples/qmake/tutorial/hellowin.cpp42
-rw-r--r--examples/qmake/tutorial/main.cpp53
-rw-r--r--examples/qtconcurrent/README38
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.cpp146
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.h81
-rw-r--r--examples/qtconcurrent/imagescaling/imagescaling.pro17
-rw-r--r--examples/qtconcurrent/imagescaling/main.cpp63
-rw-r--r--examples/qtconcurrent/map/main.cpp81
-rw-r--r--examples/qtconcurrent/map/map.pro16
-rw-r--r--examples/qtconcurrent/progressdialog/main.cpp99
-rw-r--r--examples/qtconcurrent/progressdialog/progressdialog.pro16
-rw-r--r--examples/qtconcurrent/qtconcurrent.pro17
-rw-r--r--examples/qtconcurrent/runfunction/main.cpp72
-rw-r--r--examples/qtconcurrent/runfunction/runfunction.pro16
-rw-r--r--examples/qtconcurrent/wordcount/main.cpp166
-rw-r--r--examples/qtconcurrent/wordcount/wordcount.pro16
-rw-r--r--examples/qtestlib/README38
-rw-r--r--examples/qtestlib/qtestlib.pro10
-rw-r--r--examples/qtestlib/tutorial1/testqstring.cpp64
-rw-r--r--examples/qtestlib/tutorial1/tutorial1.pro13
-rw-r--r--examples/qtestlib/tutorial2/testqstring.cpp80
-rw-r--r--examples/qtestlib/tutorial2/tutorial2.pro13
-rw-r--r--examples/qtestlib/tutorial3/testgui.cpp70
-rw-r--r--examples/qtestlib/tutorial3/tutorial3.pro13
-rw-r--r--examples/qtestlib/tutorial4/testgui.cpp90
-rw-r--r--examples/qtestlib/tutorial4/tutorial4.pro13
-rw-r--r--examples/qtestlib/tutorial5/benchmarking.cpp134
-rw-r--r--examples/qtestlib/tutorial5/containers.cpp268
-rw-r--r--examples/qtestlib/tutorial5/tutorial5.pro13
-rw-r--r--examples/qws/README38
-rw-r--r--examples/qws/dbscreen/dbscreen.cpp95
-rw-r--r--examples/qws/dbscreen/dbscreen.h66
-rw-r--r--examples/qws/dbscreen/dbscreen.pro11
-rw-r--r--examples/qws/dbscreen/dbscreendriverplugin.cpp76
-rw-r--r--examples/qws/framebuffer/framebuffer.pro11
-rw-r--r--examples/qws/framebuffer/main.c585
-rw-r--r--examples/qws/mousecalibration/calibration.cpp144
-rw-r--r--examples/qws/mousecalibration/calibration.h67
-rw-r--r--examples/qws/mousecalibration/main.cpp92
-rw-r--r--examples/qws/mousecalibration/mousecalibration.pro11
-rw-r--r--examples/qws/mousecalibration/scribblewidget.cpp92
-rw-r--r--examples/qws/mousecalibration/scribblewidget.h70
-rw-r--r--examples/qws/qws.pro9
-rw-r--r--examples/qws/simpledecoration/analogclock.cpp110
-rw-r--r--examples/qws/simpledecoration/analogclock.h57
-rw-r--r--examples/qws/simpledecoration/main.cpp59
-rw-r--r--examples/qws/simpledecoration/mydecoration.cpp374
-rw-r--r--examples/qws/simpledecoration/mydecoration.h72
-rw-r--r--examples/qws/simpledecoration/simpledecoration.pro12
-rw-r--r--examples/qws/svgalib/README9
-rw-r--r--examples/qws/svgalib/svgalib.pro19
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.cpp66
-rw-r--r--examples/qws/svgalib/svgalibpaintdevice.h65
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.cpp190
-rw-r--r--examples/qws/svgalib/svgalibpaintengine.h78
-rw-r--r--examples/qws/svgalib/svgalibplugin.cpp74
-rw-r--r--examples/qws/svgalib/svgalibscreen.cpp353
-rw-r--r--examples/qws/svgalib/svgalibscreen.h83
-rw-r--r--examples/qws/svgalib/svgalibsurface.cpp86
-rw-r--r--examples/qws/svgalib/svgalibsurface.h75
-rw-r--r--examples/richtext/README42
-rw-r--r--examples/richtext/calendar/calendar.pro11
-rw-r--r--examples/richtext/calendar/main.cpp52
-rw-r--r--examples/richtext/calendar/mainwindow.cpp214
-rw-r--r--examples/richtext/calendar/mainwindow.h73
-rw-r--r--examples/richtext/orderform/detailsdialog.cpp156
-rw-r--r--examples/richtext/orderform/detailsdialog.h90
-rw-r--r--examples/richtext/orderform/main.cpp55
-rw-r--r--examples/richtext/orderform/mainwindow.cpp249
-rw-r--r--examples/richtext/orderform/mainwindow.h76
-rw-r--r--examples/richtext/orderform/orderform.pro13
-rw-r--r--examples/richtext/richtext.pro14
-rw-r--r--examples/richtext/syntaxhighlighter/highlighter.cpp147
-rw-r--r--examples/richtext/syntaxhighlighter/highlighter.h84
-rw-r--r--examples/richtext/syntaxhighlighter/main.cpp52
-rw-r--r--examples/richtext/syntaxhighlighter/mainwindow.cpp128
-rw-r--r--examples/richtext/syntaxhighlighter/mainwindow.h75
-rw-r--r--examples/richtext/syntaxhighlighter/syntaxhighlighter.pro19
-rw-r--r--examples/scroller/graphicsview/graphicsview.pro8
-rw-r--r--examples/scroller/graphicsview/main.cpp295
-rw-r--r--examples/scroller/scroller.pro2
-rw-r--r--examples/sql/README40
-rw-r--r--examples/sql/cachedtable/cachedtable.pro13
-rw-r--r--examples/sql/cachedtable/main.cpp57
-rw-r--r--examples/sql/cachedtable/tableeditor.cpp105
-rw-r--r--examples/sql/cachedtable/tableeditor.h72
-rw-r--r--examples/sql/connection.h135
-rw-r--r--examples/sql/drilldown/drilldown.pro21
-rw-r--r--examples/sql/drilldown/drilldown.qrc11
-rw-r--r--examples/sql/drilldown/imageitem.cpp123
-rw-r--r--examples/sql/drilldown/imageitem.h74
-rw-r--r--examples/sql/drilldown/images/beijing.pngbin0 -> 99093 bytes
-rw-r--r--examples/sql/drilldown/images/berlin.pngbin0 -> 81944 bytes
-rw-r--r--examples/sql/drilldown/images/brisbane.pngbin0 -> 57785 bytes
-rw-r--r--examples/sql/drilldown/images/munich.pngbin0 -> 59769 bytes
-rw-r--r--examples/sql/drilldown/images/oslo.pngbin0 -> 41781 bytes
-rw-r--r--examples/sql/drilldown/images/redwood.pngbin0 -> 39050 bytes
-rw-r--r--examples/sql/drilldown/informationwindow.cpp167
-rw-r--r--examples/sql/drilldown/informationwindow.h90
-rw-r--r--examples/sql/drilldown/logo.pngbin0 -> 13378 bytes
-rw-r--r--examples/sql/drilldown/main.cpp65
-rw-r--r--examples/sql/drilldown/view.cpp191
-rw-r--r--examples/sql/drilldown/view.h80
-rw-r--r--examples/sql/masterdetail/albumdetails.xml98
-rw-r--r--examples/sql/masterdetail/database.h96
-rw-r--r--examples/sql/masterdetail/dialog.cpp282
-rw-r--r--examples/sql/masterdetail/dialog.h82
-rw-r--r--examples/sql/masterdetail/images/icon.pngbin0 -> 30095 bytes
-rw-r--r--examples/sql/masterdetail/images/image.pngbin0 -> 166692 bytes
-rw-r--r--examples/sql/masterdetail/main.cpp59
-rw-r--r--examples/sql/masterdetail/mainwindow.cpp429
-rw-r--r--examples/sql/masterdetail/mainwindow.h103
-rw-r--r--examples/sql/masterdetail/masterdetail.pro21
-rw-r--r--examples/sql/masterdetail/masterdetail.qrc6
-rw-r--r--examples/sql/querymodel/customsqlmodel.cpp64
-rw-r--r--examples/sql/querymodel/customsqlmodel.h58
-rw-r--r--examples/sql/querymodel/editablesqlmodel.cpp109
-rw-r--r--examples/sql/querymodel/editablesqlmodel.h62
-rw-r--r--examples/sql/querymodel/main.cpp86
-rw-r--r--examples/sql/querymodel/querymodel.pro15
-rw-r--r--examples/sql/relationaltablemodel/relationaltablemodel.cpp114
-rw-r--r--examples/sql/relationaltablemodel/relationaltablemodel.pro11
-rw-r--r--examples/sql/sql.pro20
-rw-r--r--examples/sql/sqlwidgetmapper/main.cpp51
-rw-r--r--examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro13
-rw-r--r--examples/sql/sqlwidgetmapper/window.cpp158
-rw-r--r--examples/sql/sqlwidgetmapper/window.h89
-rw-r--r--examples/sql/tablemodel/tablemodel.cpp83
-rw-r--r--examples/sql/tablemodel/tablemodel.pro11
-rw-r--r--examples/statemachine/README36
-rw-r--r--examples/statemachine/eventtransitions/eventtransitions.pro7
-rw-r--r--examples/statemachine/eventtransitions/main.cpp110
-rw-r--r--examples/statemachine/factorial/factorial.pro11
-rw-r--r--examples/statemachine/factorial/main.cpp175
-rw-r--r--examples/statemachine/pingpong/main.cpp139
-rw-r--r--examples/statemachine/pingpong/pingpong.pro11
-rw-r--r--examples/statemachine/rogue/main.cpp54
-rw-r--r--examples/statemachine/rogue/movementtransition.h107
-rw-r--r--examples/statemachine/rogue/rogue.pro11
-rw-r--r--examples/statemachine/rogue/window.cpp200
-rw-r--r--examples/statemachine/rogue/window.h90
-rw-r--r--examples/statemachine/statemachine.pro18
-rw-r--r--examples/statemachine/trafficlight/main.cpp184
-rw-r--r--examples/statemachine/trafficlight/trafficlight.pro7
-rw-r--r--examples/statemachine/twowaybutton/main.cpp81
-rw-r--r--examples/statemachine/twowaybutton/twowaybutton.pro7
-rw-r--r--examples/symbianpkgrules.pri20
-rw-r--r--examples/threads/README40
-rw-r--r--examples/threads/mandelbrot/main.cpp53
-rw-r--r--examples/threads/mandelbrot/mandelbrot.pro15
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.cpp239
-rw-r--r--examples/threads/mandelbrot/mandelbrotwidget.h84
-rw-r--r--examples/threads/mandelbrot/renderthread.cpp215
-rw-r--r--examples/threads/mandelbrot/renderthread.h88
-rw-r--r--examples/threads/queuedcustomtype/block.cpp73
-rw-r--r--examples/threads/queuedcustomtype/block.h70
-rw-r--r--examples/threads/queuedcustomtype/main.cpp128
-rw-r--r--examples/threads/queuedcustomtype/queuedcustomtype.pro7
-rw-r--r--examples/threads/queuedcustomtype/renderthread.cpp109
-rw-r--r--examples/threads/queuedcustomtype/renderthread.h76
-rw-r--r--examples/threads/queuedcustomtype/window.cpp136
-rw-r--r--examples/threads/queuedcustomtype/window.h76
-rw-r--r--examples/threads/semaphores/semaphores.cpp106
-rw-r--r--examples/threads/semaphores/semaphores.pro12
-rw-r--r--examples/threads/threads.pro13
-rw-r--r--examples/threads/waitconditions/waitconditions.cpp125
-rw-r--r--examples/threads/waitconditions/waitconditions.pro21
-rw-r--r--examples/tools/README40
-rw-r--r--examples/tools/codecs/codecs.pro13
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-1.txt6
-rw-r--r--examples/tools/codecs/encodedfiles/iso-8859-15.txt8
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16.txtbin0 -> 162 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16be.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-16le.txtbin0 -> 160 bytes
-rw-r--r--examples/tools/codecs/encodedfiles/utf-8.txt6
-rw-r--r--examples/tools/codecs/main.cpp51
-rw-r--r--examples/tools/codecs/mainwindow.cpp202
-rw-r--r--examples/tools/codecs/mainwindow.h87
-rw-r--r--examples/tools/codecs/previewform.cpp101
-rw-r--r--examples/tools/codecs/previewform.h79
-rw-r--r--examples/tools/completer/completer.pro14
-rw-r--r--examples/tools/completer/completer.qrc6
-rw-r--r--examples/tools/completer/fsmodel.cpp63
-rw-r--r--examples/tools/completer/fsmodel.h60
-rw-r--r--examples/tools/completer/main.cpp54
-rw-r--r--examples/tools/completer/mainwindow.cpp281
-rw-r--r--examples/tools/completer/mainwindow.h89
-rw-r--r--examples/tools/completer/resources/countries.txt241
-rw-r--r--examples/tools/completer/resources/wordlist.txt1485
-rw-r--r--examples/tools/contiguouscache/contiguouscache.pro9
-rw-r--r--examples/tools/contiguouscache/main.cpp55
-rw-r--r--examples/tools/contiguouscache/randomlistmodel.cpp96
-rw-r--r--examples/tools/contiguouscache/randomlistmodel.h65
-rw-r--r--examples/tools/customcompleter/customcompleter.pro14
-rw-r--r--examples/tools/customcompleter/customcompleter.qrc5
-rw-r--r--examples/tools/customcompleter/main.cpp54
-rw-r--r--examples/tools/customcompleter/mainwindow.cpp117
-rw-r--r--examples/tools/customcompleter/mainwindow.h76
-rw-r--r--examples/tools/customcompleter/resources/wordlist.txt1454
-rw-r--r--examples/tools/customcompleter/textedit.cpp173
-rw-r--r--examples/tools/customcompleter/textedit.h78
-rw-r--r--examples/tools/customtype/customtype.pro3
-rw-r--r--examples/tools/customtype/main.cpp73
-rw-r--r--examples/tools/customtype/message.cpp89
-rw-r--r--examples/tools/customtype/message.h75
-rw-r--r--examples/tools/customtypesending/customtypesending.pro5
-rw-r--r--examples/tools/customtypesending/main.cpp67
-rw-r--r--examples/tools/customtypesending/message.cpp71
-rw-r--r--examples/tools/customtypesending/message.h71
-rw-r--r--examples/tools/customtypesending/window.cpp79
-rw-r--r--examples/tools/customtypesending/window.h72
-rw-r--r--examples/tools/echoplugin/echoplugin.pro13
-rw-r--r--examples/tools/echoplugin/echowindow/echointerface.h61
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.cpp118
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.h79
-rw-r--r--examples/tools/echoplugin/echowindow/echowindow.pro21
-rw-r--r--examples/tools/echoplugin/echowindow/main.cpp56
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.cpp54
-rw-r--r--examples/tools/echoplugin/plugin/echoplugin.h59
-rw-r--r--examples/tools/echoplugin/plugin/plugin.pro19
-rw-r--r--examples/tools/i18n/i18n.pro28
-rw-r--r--examples/tools/i18n/i18n.qrc18
-rw-r--r--examples/tools/i18n/languagechooser.cpp166
-rw-r--r--examples/tools/i18n/languagechooser.h85
-rw-r--r--examples/tools/i18n/main.cpp54
-rw-r--r--examples/tools/i18n/mainwindow.cpp95
-rw-r--r--examples/tools/i18n/mainwindow.h76
-rw-r--r--examples/tools/i18n/translations/i18n_ar.qmbin0 -> 736 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ar.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_cs.qmbin0 -> 796 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_cs.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_de.qmbin0 -> 848 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_de.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_el.qmbin0 -> 804 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_el.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_en.qmbin0 -> 810 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_en.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_eo.qmbin0 -> 806 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_eo.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_fr.qmbin0 -> 844 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_fr.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_it.qmbin0 -> 808 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_it.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_jp.qmbin0 -> 722 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_jp.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_ko.qmbin0 -> 690 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ko.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_no.qmbin0 -> 804 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_no.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_ru.qmbin0 -> 806 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_ru.ts59
-rw-r--r--examples/tools/i18n/translations/i18n_sv.qmbin0 -> 814 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_sv.ts57
-rw-r--r--examples/tools/i18n/translations/i18n_zh.qmbin0 -> 700 bytes
-rw-r--r--examples/tools/i18n/translations/i18n_zh.ts57
-rw-r--r--examples/tools/inputpanel/inputpanel.pro17
-rw-r--r--examples/tools/inputpanel/main.cpp61
-rw-r--r--examples/tools/inputpanel/mainform.ui76
-rw-r--r--examples/tools/inputpanel/myinputpanel.cpp133
-rw-r--r--examples/tools/inputpanel/myinputpanel.h76
-rw-r--r--examples/tools/inputpanel/myinputpanelcontext.cpp131
-rw-r--r--examples/tools/inputpanel/myinputpanelcontext.h81
-rw-r--r--examples/tools/inputpanel/myinputpanelform.ui398
-rw-r--r--examples/tools/plugandpaint/interfaces.h110
-rw-r--r--examples/tools/plugandpaint/main.cpp57
-rw-r--r--examples/tools/plugandpaint/mainwindow.cpp309
-rw-r--r--examples/tools/plugandpaint/mainwindow.h103
-rw-r--r--examples/tools/plugandpaint/paintarea.cpp195
-rw-r--r--examples/tools/plugandpaint/paintarea.h91
-rw-r--r--examples/tools/plugandpaint/plugandpaint.pro28
-rw-r--r--examples/tools/plugandpaint/plugindialog.cpp156
-rw-r--r--examples/tools/plugandpaint/plugindialog.h76
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictools.pro17
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp197
-rw-r--r--examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h87
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro19
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp124
-rw-r--r--examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h63
-rw-r--r--examples/tools/plugandpaintplugins/plugandpaintplugins.pro11
-rw-r--r--examples/tools/regexp/main.cpp51
-rw-r--r--examples/tools/regexp/regexp.pro11
-rw-r--r--examples/tools/regexp/regexpdialog.cpp188
-rw-r--r--examples/tools/regexp/regexpdialog.h85
-rw-r--r--examples/tools/settingseditor/inifiles/licensepage.ini46
-rw-r--r--examples/tools/settingseditor/inifiles/qsa.ini26
-rw-r--r--examples/tools/settingseditor/locationdialog.cpp216
-rw-r--r--examples/tools/settingseditor/locationdialog.h84
-rw-r--r--examples/tools/settingseditor/main.cpp51
-rw-r--r--examples/tools/settingseditor/mainwindow.cpp222
-rw-r--r--examples/tools/settingseditor/mainwindow.h91
-rw-r--r--examples/tools/settingseditor/settingseditor.pro17
-rw-r--r--examples/tools/settingseditor/settingstree.cpp262
-rw-r--r--examples/tools/settingseditor/settingstree.h90
-rw-r--r--examples/tools/settingseditor/variantdelegate.cpp316
-rw-r--r--examples/tools/settingseditor/variantdelegate.h81
-rw-r--r--examples/tools/styleplugin/plugin/plugin.pro25
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.cpp48
-rw-r--r--examples/tools/styleplugin/plugin/simplestyle.h60
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.cpp64
-rw-r--r--examples/tools/styleplugin/plugin/simplestyleplugin.h64
-rw-r--r--examples/tools/styleplugin/styleplugin.pro11
-rw-r--r--examples/tools/styleplugin/stylewindow/main.cpp57
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.cpp60
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.h54
-rw-r--r--examples/tools/styleplugin/stylewindow/stylewindow.pro19
-rw-r--r--examples/tools/tools.pro26
-rw-r--r--examples/tools/treemodelcompleter/main.cpp54
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.cpp246
-rw-r--r--examples/tools/treemodelcompleter/mainwindow.h88
-rw-r--r--examples/tools/treemodelcompleter/resources/treemodel.txt20
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.cpp97
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.h70
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.pro14
-rw-r--r--examples/tools/treemodelcompleter/treemodelcompleter.qrc5
-rw-r--r--examples/tools/undoframework/commands.cpp168
-rw-r--r--examples/tools/undoframework/commands.h104
-rw-r--r--examples/tools/undoframework/diagramitem.cpp65
-rw-r--r--examples/tools/undoframework/diagramitem.h72
-rw-r--r--examples/tools/undoframework/diagramscene.cpp75
-rw-r--r--examples/tools/undoframework/diagramscene.h74
-rw-r--r--examples/tools/undoframework/images/cross.pngbin0 -> 114 bytes
-rw-r--r--examples/tools/undoframework/main.cpp57
-rw-r--r--examples/tools/undoframework/mainwindow.cpp206
-rw-r--r--examples/tools/undoframework/mainwindow.h99
-rw-r--r--examples/tools/undoframework/undoframework.pro18
-rw-r--r--examples/tools/undoframework/undoframework.qrc6
-rw-r--r--examples/touch/dials/dials.pro8
-rw-r--r--examples/touch/dials/dials.ui77
-rw-r--r--examples/touch/dials/main.cpp58
-rw-r--r--examples/touch/fingerpaint/fingerpaint.pro11
-rw-r--r--examples/touch/fingerpaint/main.cpp51
-rw-r--r--examples/touch/fingerpaint/mainwindow.cpp217
-rw-r--r--examples/touch/fingerpaint/mainwindow.h88
-rw-r--r--examples/touch/fingerpaint/scribblearea.cpp211
-rw-r--r--examples/touch/fingerpaint/scribblearea.h80
-rw-r--r--examples/touch/knobs/knob.cpp88
-rw-r--r--examples/touch/knobs/knob.h54
-rw-r--r--examples/touch/knobs/knobs.pro8
-rw-r--r--examples/touch/knobs/main.cpp64
-rw-r--r--examples/touch/pinchzoom/graphicsview.cpp85
-rw-r--r--examples/touch/pinchzoom/graphicsview.h55
-rw-r--r--examples/touch/pinchzoom/images/cheese.jpgbin0 -> 3029 bytes
-rw-r--r--examples/touch/pinchzoom/main.cpp86
-rw-r--r--examples/touch/pinchzoom/mice.qrc5
-rw-r--r--examples/touch/pinchzoom/mouse.cpp199
-rw-r--r--examples/touch/pinchzoom/mouse.h70
-rw-r--r--examples/touch/pinchzoom/pinchzoom.pro16
-rw-r--r--examples/touch/touch.pro2
-rw-r--r--examples/tutorials/README37
-rw-r--r--examples/tutorials/addressbook-fr/README42
-rw-r--r--examples/tutorials/addressbook-fr/addressbook-fr.pro8
-rw-r--r--examples/tutorials/addressbook-fr/part1/addressbook.cpp67
-rw-r--r--examples/tutorials/addressbook-fr/part1/addressbook.h66
-rw-r--r--examples/tutorials/addressbook-fr/part1/main.cpp54
-rw-r--r--examples/tutorials/addressbook-fr/part1/part1.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part2/addressbook.cpp157
-rw-r--r--examples/tutorials/addressbook-fr/part2/addressbook.h84
-rw-r--r--examples/tutorials/addressbook-fr/part2/main.cpp54
-rw-r--r--examples/tutorials/addressbook-fr/part2/part2.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part3/addressbook.cpp215
-rw-r--r--examples/tutorials/addressbook-fr/part3/addressbook.h86
-rw-r--r--examples/tutorials/addressbook-fr/part3/main.cpp52
-rw-r--r--examples/tutorials/addressbook-fr/part3/part3.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part4/addressbook.cpp288
-rw-r--r--examples/tutorials/addressbook-fr/part4/addressbook.h99
-rw-r--r--examples/tutorials/addressbook-fr/part4/main.cpp52
-rw-r--r--examples/tutorials/addressbook-fr/part4/part4.pro9
-rw-r--r--examples/tutorials/addressbook-fr/part5/addressbook.cpp312
-rw-r--r--examples/tutorials/addressbook-fr/part5/addressbook.h102
-rw-r--r--examples/tutorials/addressbook-fr/part5/finddialog.cpp86
-rw-r--r--examples/tutorials/addressbook-fr/part5/finddialog.h68
-rw-r--r--examples/tutorials/addressbook-fr/part5/main.cpp52
-rw-r--r--examples/tutorials/addressbook-fr/part5/part5.pro11
-rw-r--r--examples/tutorials/addressbook-fr/part6/addressbook.cpp393
-rw-r--r--examples/tutorials/addressbook-fr/part6/addressbook.h103
-rw-r--r--examples/tutorials/addressbook-fr/part6/finddialog.cpp82
-rw-r--r--examples/tutorials/addressbook-fr/part6/finddialog.h68
-rw-r--r--examples/tutorials/addressbook-fr/part6/main.cpp52
-rw-r--r--examples/tutorials/addressbook-fr/part6/part6.pro11
-rw-r--r--examples/tutorials/addressbook-fr/part7/addressbook.cpp446
-rw-r--r--examples/tutorials/addressbook-fr/part7/addressbook.h105
-rw-r--r--examples/tutorials/addressbook-fr/part7/finddialog.cpp82
-rw-r--r--examples/tutorials/addressbook-fr/part7/finddialog.h68
-rw-r--r--examples/tutorials/addressbook-fr/part7/main.cpp52
-rw-r--r--examples/tutorials/addressbook-fr/part7/part7.pro11
-rw-r--r--examples/tutorials/addressbook/README42
-rw-r--r--examples/tutorials/addressbook/addressbook.pro10
-rw-r--r--examples/tutorials/addressbook/part1/addressbook.cpp67
-rw-r--r--examples/tutorials/addressbook/part1/addressbook.h66
-rw-r--r--examples/tutorials/addressbook/part1/main.cpp54
-rw-r--r--examples/tutorials/addressbook/part1/part1.pro11
-rw-r--r--examples/tutorials/addressbook/part2/addressbook.cpp157
-rw-r--r--examples/tutorials/addressbook/part2/addressbook.h84
-rw-r--r--examples/tutorials/addressbook/part2/main.cpp54
-rw-r--r--examples/tutorials/addressbook/part2/part2.pro11
-rw-r--r--examples/tutorials/addressbook/part3/addressbook.cpp215
-rw-r--r--examples/tutorials/addressbook/part3/addressbook.h86
-rw-r--r--examples/tutorials/addressbook/part3/main.cpp52
-rw-r--r--examples/tutorials/addressbook/part3/part3.pro11
-rw-r--r--examples/tutorials/addressbook/part4/addressbook.cpp288
-rw-r--r--examples/tutorials/addressbook/part4/addressbook.h99
-rw-r--r--examples/tutorials/addressbook/part4/main.cpp52
-rw-r--r--examples/tutorials/addressbook/part4/part4.pro11
-rw-r--r--examples/tutorials/addressbook/part5/addressbook.cpp312
-rw-r--r--examples/tutorials/addressbook/part5/addressbook.h102
-rw-r--r--examples/tutorials/addressbook/part5/finddialog.cpp86
-rw-r--r--examples/tutorials/addressbook/part5/finddialog.h68
-rw-r--r--examples/tutorials/addressbook/part5/main.cpp52
-rw-r--r--examples/tutorials/addressbook/part5/part5.pro13
-rw-r--r--examples/tutorials/addressbook/part6/addressbook.cpp393
-rw-r--r--examples/tutorials/addressbook/part6/addressbook.h103
-rw-r--r--examples/tutorials/addressbook/part6/finddialog.cpp82
-rw-r--r--examples/tutorials/addressbook/part6/finddialog.h68
-rw-r--r--examples/tutorials/addressbook/part6/main.cpp52
-rw-r--r--examples/tutorials/addressbook/part6/part6.pro13
-rw-r--r--examples/tutorials/addressbook/part7/addressbook.cpp446
-rw-r--r--examples/tutorials/addressbook/part7/addressbook.h105
-rw-r--r--examples/tutorials/addressbook/part7/finddialog.cpp82
-rw-r--r--examples/tutorials/addressbook/part7/finddialog.h68
-rw-r--r--examples/tutorials/addressbook/part7/main.cpp52
-rw-r--r--examples/tutorials/addressbook/part7/part7.pro13
-rw-r--r--examples/tutorials/gettingStarted/gettingStarted.pro2
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/gsqt.pro13
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/part1/main.cpp53
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/part2/main.cpp63
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/part3/main.cpp97
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/part4/main.cpp108
-rwxr-xr-xexamples/tutorials/gettingStarted/gsQt/part5/main.cpp134
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/1_readonly.pro17
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/main.cpp56
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.cpp70
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.h59
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/2_formatting.pro16
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/main.cpp56
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/mymodel.cpp112
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/mymodel.h56
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/3_changingmodel.pro16
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/main.cpp53
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/mymodel.cpp94
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/mymodel.h62
-rwxr-xr-xexamples/tutorials/modelview/4_headers/4_headers.pro16
-rwxr-xr-xexamples/tutorials/modelview/4_headers/main.cpp53
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.cpp91
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.h57
-rwxr-xr-xexamples/tutorials/modelview/5_edit/5_edit.pro18
-rwxr-xr-xexamples/tutorials/modelview/5_edit/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mainwindow.cpp60
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mainwindow.h62
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.cpp101
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.h70
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/6_treeview.pro13
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/mainwindow.cpp82
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/mainwindow.h66
-rwxr-xr-xexamples/tutorials/modelview/7_selections/7_selections.pro13
-rwxr-xr-xexamples/tutorials/modelview/7_selections/main.cpp50
-rwxr-xr-xexamples/tutorials/modelview/7_selections/mainwindow.cpp109
-rwxr-xr-xexamples/tutorials/modelview/7_selections/mainwindow.h65
-rwxr-xr-xexamples/tutorials/modelview/modelview.pro16
-rwxr-xr-xexamples/tutorials/threads/clock/clock.pro14
-rw-r--r--examples/tutorials/threads/clock/clockthread.cpp66
-rw-r--r--examples/tutorials/threads/clock/clockthread.h64
-rwxr-xr-xexamples/tutorials/threads/clock/main.cpp67
-rwxr-xr-xexamples/tutorials/threads/helloconcurrent/helloconcurrent.cpp61
-rwxr-xr-xexamples/tutorials/threads/helloconcurrent/helloconcurrent.pro16
-rwxr-xr-xexamples/tutorials/threads/hellothread/hellothread.cpp53
-rwxr-xr-xexamples/tutorials/threads/hellothread/hellothread.h54
-rwxr-xr-xexamples/tutorials/threads/hellothread/hellothread.pro17
-rwxr-xr-xexamples/tutorials/threads/hellothread/main.cpp54
-rwxr-xr-xexamples/tutorials/threads/hellothreadpool/hellothreadpool.cpp65
-rwxr-xr-xexamples/tutorials/threads/hellothreadpool/hellothreadpool.pro17
-rwxr-xr-xexamples/tutorials/threads/movedobject/main.cpp69
-rwxr-xr-xexamples/tutorials/threads/movedobject/movedobject.pro18
-rw-r--r--examples/tutorials/threads/movedobject/thread.cpp101
-rw-r--r--examples/tutorials/threads/movedobject/thread.h67
-rw-r--r--examples/tutorials/threads/movedobject/workerobject.cpp87
-rw-r--r--examples/tutorials/threads/movedobject/workerobject.h64
-rw-r--r--examples/tutorials/threads/threads.pro8
-rw-r--r--examples/tutorials/tutorials.pro2
-rw-r--r--examples/tutorials/widgets/childwidget/childwidget.pro7
-rw-r--r--examples/tutorials/widgets/childwidget/main.cpp60
-rw-r--r--examples/tutorials/widgets/nestedlayouts/main.cpp103
-rw-r--r--examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro7
-rw-r--r--examples/tutorials/widgets/toplevel/main.cpp56
-rw-r--r--examples/tutorials/widgets/toplevel/toplevel.pro7
-rw-r--r--examples/tutorials/widgets/widgets.pro8
-rw-r--r--examples/tutorials/widgets/windowlayout/main.cpp62
-rw-r--r--examples/tutorials/widgets/windowlayout/windowlayout.pro7
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.cpp65
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.h62
-rw-r--r--examples/uitools/multipleinheritance/calculatorform.ui303
-rw-r--r--examples/uitools/multipleinheritance/main.cpp52
-rw-r--r--examples/uitools/multipleinheritance/multipleinheritance.pro16
-rw-r--r--examples/uitools/textfinder/forms/input.txt9
-rw-r--r--examples/uitools/textfinder/forms/textfinder.ui89
-rw-r--r--examples/uitools/textfinder/main.cpp55
-rw-r--r--examples/uitools/textfinder/textfinder.cpp155
-rw-r--r--examples/uitools/textfinder/textfinder.h74
-rw-r--r--examples/uitools/textfinder/textfinder.pro12
-rw-r--r--examples/uitools/textfinder/textfinder.qrc6
-rw-r--r--examples/uitools/uitools.pro12
-rw-r--r--examples/webkit/webkit-guide/_copyright.txt40
-rw-r--r--examples/webkit/webkit-guide/_image_assets.htm331
-rw-r--r--examples/webkit/webkit-guide/_index.html322
-rw-r--r--examples/webkit/webkit-guide/anim_accord.htm122
-rw-r--r--examples/webkit/webkit-guide/anim_demo-rotate.htm63
-rw-r--r--examples/webkit/webkit-guide/anim_demo-scale.htm67
-rw-r--r--examples/webkit/webkit-guide/anim_demo-skew.htm62
-rw-r--r--examples/webkit/webkit-guide/anim_gallery.htm114
-rw-r--r--examples/webkit/webkit-guide/anim_panel.htm63
-rw-r--r--examples/webkit/webkit-guide/anim_pulse.htm71
-rw-r--r--examples/webkit/webkit-guide/anim_skew.htm80
-rw-r--r--examples/webkit/webkit-guide/anim_slide1.htm61
-rw-r--r--examples/webkit/webkit-guide/anim_slide2.htm62
-rw-r--r--examples/webkit/webkit-guide/anim_slide3.htm65
-rw-r--r--examples/webkit/webkit-guide/anim_tabbedSkew.htm88
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_accord.css246
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_demo-rotate.css95
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_demo-scale.css112
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_demo-skew.css98
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_gallery.css110
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_panel.css116
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_pulse.css100
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_skew.css186
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_slide.css148
-rwxr-xr-xexamples/webkit/webkit-guide/css/anim_tabbedSkew.css113
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_backgrounds.css105
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_border-img.css70
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_grad-radial.css66
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_gradientBack.css77
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_gradientBackStop.css77
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_gradientButton.css88
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_mask-grad.css60
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_mask-img.css58
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_multicol.css110
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_reflect.css127
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_scroll.css93
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_sel-nth.css63
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_shadow.css145
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_shadowBlur.css145
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_text-overflow.css119
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_text-shadow.css67
-rwxr-xr-xexamples/webkit/webkit-guide/css/css3_text-stroke.css75
-rwxr-xr-xexamples/webkit/webkit-guide/css/form_tapper.css108
-rwxr-xr-xexamples/webkit/webkit-guide/css/form_toggler.css200
-rwxr-xr-xexamples/webkit/webkit-guide/css/layout_link-fmt.css137
-rwxr-xr-xexamples/webkit/webkit-guide/css/layout_tbl-keyhole.css147
-rwxr-xr-xexamples/webkit/webkit-guide/css/mob_condjs.css55
-rwxr-xr-xexamples/webkit/webkit-guide/css/mob_mediaquery.css49
-rwxr-xr-xexamples/webkit/webkit-guide/css/mobile.css82
-rwxr-xr-xexamples/webkit/webkit-guide/css/mq_desktop.css70
-rwxr-xr-xexamples/webkit/webkit-guide/css/mq_mobile.css69
-rwxr-xr-xexamples/webkit/webkit-guide/css/mq_touch.css69
-rwxr-xr-xexamples/webkit/webkit-guide/css/mqlayout_desktop.css92
-rwxr-xr-xexamples/webkit/webkit-guide/css/mqlayout_mobile.css82
-rwxr-xr-xexamples/webkit/webkit-guide/css/mqlayout_touch.css86
-rwxr-xr-xexamples/webkit/webkit-guide/css/storage.css156
-rw-r--r--examples/webkit/webkit-guide/css3_backgrounds.htm87
-rw-r--r--examples/webkit/webkit-guide/css3_border-img.htm78
-rw-r--r--examples/webkit/webkit-guide/css3_grad-radial.htm61
-rw-r--r--examples/webkit/webkit-guide/css3_gradientBack.htm79
-rw-r--r--examples/webkit/webkit-guide/css3_gradientBackStop.htm92
-rw-r--r--examples/webkit/webkit-guide/css3_gradientButton.htm66
-rw-r--r--examples/webkit/webkit-guide/css3_mask-grad.htm66
-rw-r--r--examples/webkit/webkit-guide/css3_mask-img.htm56
-rw-r--r--examples/webkit/webkit-guide/css3_multicol.htm91
-rw-r--r--examples/webkit/webkit-guide/css3_reflect.htm100
-rw-r--r--examples/webkit/webkit-guide/css3_scroll.htm94
-rw-r--r--examples/webkit/webkit-guide/css3_sel-nth.htm80
-rw-r--r--examples/webkit/webkit-guide/css3_shadow.htm78
-rw-r--r--examples/webkit/webkit-guide/css3_text-overflow.htm117
-rw-r--r--examples/webkit/webkit-guide/css3_text-shadow.htm74
-rw-r--r--examples/webkit/webkit-guide/css3_text-stroke.htm74
-rw-r--r--examples/webkit/webkit-guide/form_tapper.htm74
-rw-r--r--examples/webkit/webkit-guide/form_toggler.htm140
-rwxr-xr-xexamples/webkit/webkit-guide/img/border-frame.pngbin0 -> 5534 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal1.jpgbin0 -> 44584 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal2.jpgbin0 -> 45495 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal3.jpgbin0 -> 51291 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal4.jpgbin0 -> 57195 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal5.jpgbin0 -> 31293 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal6.jpgbin0 -> 30854 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal7.jpgbin0 -> 35211 bytes
-rw-r--r--examples/webkit/webkit-guide/img/gal8.jpgbin0 -> 35269 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/gradient.jpgbin0 -> 710 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/gray_icon_close.pngbin0 -> 658 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ag_016.pngbin0 -> 598 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ag_032.pngbin0 -> 1275 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ag_036.pngbin0 -> 1803 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ag_048.pngbin0 -> 1885 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_al_016.pngbin0 -> 625 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_al_032.pngbin0 -> 1259 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_al_036.pngbin0 -> 1755 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_al_048.pngbin0 -> 1795 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ar_016.pngbin0 -> 608 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ar_032.pngbin0 -> 1233 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ar_036.pngbin0 -> 1777 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ar_048.pngbin0 -> 1828 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_b_016.pngbin0 -> 580 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_b_032.pngbin0 -> 1166 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_b_036.pngbin0 -> 1668 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_b_048.pngbin0 -> 1623 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_be_016.pngbin0 -> 614 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_be_032.pngbin0 -> 1322 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_be_036.pngbin0 -> 1811 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_be_048.pngbin0 -> 1824 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_c_016.pngbin0 -> 545 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_c_032.pngbin0 -> 1102 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_c_036.pngbin0 -> 1595 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_c_048.pngbin0 -> 1622 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ca_016.pngbin0 -> 606 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ca_032.pngbin0 -> 1229 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ca_036.pngbin0 -> 1771 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ca_048.pngbin0 -> 1820 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cl_016.pngbin0 -> 602 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cl_032.pngbin0 -> 1197 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cl_036.pngbin0 -> 1731 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cl_048.pngbin0 -> 1816 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cu_016.pngbin0 -> 580 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cu_032.pngbin0 -> 1183 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cu_036.pngbin0 -> 1742 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_cu_048.pngbin0 -> 1729 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_f_016.pngbin0 -> 539 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_f_032.pngbin0 -> 1047 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_f_036.pngbin0 -> 1487 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_f_048.pngbin0 -> 1488 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_fe_016.pngbin0 -> 591 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_fe_032.pngbin0 -> 1171 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_fe_036.pngbin0 -> 1726 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_fe_048.pngbin0 -> 1745 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_h_016.pngbin0 -> 583 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_h_032.pngbin0 -> 1135 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_h_036.pngbin0 -> 1600 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_h_048.pngbin0 -> 1644 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_he_016.pngbin0 -> 606 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_he_032.pngbin0 -> 1179 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_he_036.pngbin0 -> 1746 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_he_048.pngbin0 -> 1675 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_k_016.pngbin0 -> 600 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_k_032.pngbin0 -> 1189 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_k_036.pngbin0 -> 1657 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_k_048.pngbin0 -> 1706 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_li_016.pngbin0 -> 584 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_li_032.pngbin0 -> 1125 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_li_036.pngbin0 -> 1596 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_li_048.pngbin0 -> 1691 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_mg_016.pngbin0 -> 628 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_mg_032.pngbin0 -> 1286 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_mg_036.pngbin0 -> 1832 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_mg_048.pngbin0 -> 1908 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_n_016.pngbin0 -> 605 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_n_032.pngbin0 -> 1203 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_n_036.pngbin0 -> 1728 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_n_048.pngbin0 -> 1718 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_na_016.pngbin0 -> 609 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_na_032.pngbin0 -> 1302 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_na_036.pngbin0 -> 1811 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_na_048.pngbin0 -> 1879 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ne_016.pngbin0 -> 619 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ne_032.pngbin0 -> 1278 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ne_036.pngbin0 -> 1798 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ne_048.pngbin0 -> 1811 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ni_016.pngbin0 -> 627 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ni_032.pngbin0 -> 1248 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ni_036.pngbin0 -> 1805 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_ni_048.pngbin0 -> 1837 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_o_016.pngbin0 -> 580 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_o_032.pngbin0 -> 1182 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_o_036.pngbin0 -> 1668 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_o_048.pngbin0 -> 1752 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_pt_016.pngbin0 -> 600 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_pt_032.pngbin0 -> 1212 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_pt_036.pngbin0 -> 1728 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_pt_048.pngbin0 -> 1675 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_si_016.pngbin0 -> 588 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_si_032.pngbin0 -> 1198 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_si_036.pngbin0 -> 1761 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_si_048.pngbin0 -> 1820 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_zn_016.pngbin0 -> 572 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_zn_032.pngbin0 -> 1164 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_zn_036.pngbin0 -> 1689 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/ic_zn_048.pngbin0 -> 1721 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_check.pngbin0 -> 678 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_check_x24green.pngbin0 -> 776 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_dismiss.pngbin0 -> 613 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_dismiss_x22.pngbin0 -> 539 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_drill-down.pngbin0 -> 605 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_drill-down_x32.pngbin0 -> 3593 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_drill-up.pngbin0 -> 592 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_drill-up_x32.pngbin0 -> 3685 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_expand-nav.pngbin0 -> 675 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_head-collapsed.pngbin0 -> 285 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_head-collapsed_x13.pngbin0 -> 201 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_head-expanded.pngbin0 -> 295 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_head-expanded_x13.pngbin0 -> 3017 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_info.pngbin0 -> 512 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_info_x24.pngbin0 -> 652 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-doc.pngbin0 -> 610 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-email.pngbin0 -> 542 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-external.pngbin0 -> 1106 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-pdf.pngbin0 -> 637 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-ppt.pngbin0 -> 536 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-rss.pngbin0 -> 684 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-sms.pngbin0 -> 1086 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-tel.pngbin0 -> 1205 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_link-xls.pngbin0 -> 603 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_list-all.pngbin0 -> 545 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_list-all_circ.pngbin0 -> 665 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_nav-start.pngbin0 -> 594 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_nav-top.pngbin0 -> 634 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_nav-up.pngbin0 -> 551 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_nav_end.pngbin0 -> 643 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_question.pngbin0 -> 802 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_scroll-left.pngbin0 -> 660 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_scroll-right.pngbin0 -> 682 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/icon_trash.pngbin0 -> 717 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land1.jpgbin0 -> 40695 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land2.jpgbin0 -> 38387 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land3.jpgbin0 -> 27180 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land4.jpgbin0 -> 45132 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land5.jpgbin0 -> 85110 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land6.jpgbin0 -> 38369 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land7.jpgbin0 -> 38923 bytes
-rw-r--r--examples/webkit/webkit-guide/img/land8.jpgbin0 -> 54475 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/img/mask.pngbin0 -> 5842 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal1.jpgbin0 -> 44584 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal2.jpgbin0 -> 45495 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal3.jpgbin0 -> 51291 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal4.jpgbin0 -> 57195 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal5.jpgbin0 -> 31293 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal6.jpgbin0 -> 30854 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal7.jpgbin0 -> 35211 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/gal8.jpgbin0 -> 35269 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land1.jpgbin0 -> 40695 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land2.jpgbin0 -> 38387 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land3.jpgbin0 -> 27180 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land4.jpgbin0 -> 45132 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land5.jpgbin0 -> 85110 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land6.jpgbin0 -> 38369 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land7.jpgbin0 -> 38923 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tmp/land8.jpgbin0 -> 54475 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal1.pngbin0 -> 16437 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal2.pngbin0 -> 14736 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal3.pngbin0 -> 15882 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal4.pngbin0 -> 18863 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal5.pngbin0 -> 15854 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal6.pngbin0 -> 17339 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal7.pngbin0 -> 17102 bytes
-rw-r--r--examples/webkit/webkit-guide/img/tnail_gal8.pngbin0 -> 17933 bytes
-rwxr-xr-xexamples/webkit/webkit-guide/js/anim_accord.js78
-rwxr-xr-xexamples/webkit/webkit-guide/js/anim_gallery.js79
-rwxr-xr-xexamples/webkit/webkit-guide/js/anim_panel.js53
-rwxr-xr-xexamples/webkit/webkit-guide/js/anim_skew.js97
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_backgrounds.js49
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_border-img.js44
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_grad-radial.js75
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_mask-grad.js44
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_mask-img.js44
-rwxr-xr-xexamples/webkit/webkit-guide/js/css3_text-overflow.js54
-rwxr-xr-xexamples/webkit/webkit-guide/js/form_tapper.js57
-rwxr-xr-xexamples/webkit/webkit-guide/js/mob_condjs.js79
-rwxr-xr-xexamples/webkit/webkit-guide/js/mobile.js50
-rwxr-xr-xexamples/webkit/webkit-guide/js/storage.js94
-rw-r--r--examples/webkit/webkit-guide/layout_link-fmt.htm81
-rw-r--r--examples/webkit/webkit-guide/layout_tbl-keyhole.htm141
-rw-r--r--examples/webkit/webkit-guide/mob_condjs.htm65
-rw-r--r--examples/webkit/webkit-guide/mob_layout.htm59
-rw-r--r--examples/webkit/webkit-guide/mob_mediaquery.htm59
-rw-r--r--examples/webkit/webkit-guide/storage.htm71
-rw-r--r--examples/webkit/webkit-guide/webkit-guide.pro257
-rw-r--r--examples/widgets/README44
-rw-r--r--examples/widgets/analogclock/analogclock.cpp145
-rw-r--r--examples/widgets/analogclock/analogclock.h59
-rw-r--r--examples/widgets/analogclock/analogclock.pro14
-rw-r--r--examples/widgets/analogclock/main.cpp51
-rw-r--r--examples/widgets/calculator/button.cpp63
-rw-r--r--examples/widgets/calculator/button.h58
-rw-r--r--examples/widgets/calculator/calculator.cpp397
-rw-r--r--examples/widgets/calculator/calculator.h107
-rw-r--r--examples/widgets/calculator/calculator.pro16
-rw-r--r--examples/widgets/calculator/main.cpp51
-rw-r--r--examples/widgets/calendarwidget/calendarwidget.pro14
-rw-r--r--examples/widgets/calendarwidget/main.cpp51
-rw-r--r--examples/widgets/calendarwidget/window.cpp461
-rw-r--r--examples/widgets/calendarwidget/window.h127
-rw-r--r--examples/widgets/charactermap/charactermap.pro13
-rw-r--r--examples/widgets/charactermap/characterwidget.cpp177
-rw-r--r--examples/widgets/charactermap/characterwidget.h86
-rw-r--r--examples/widgets/charactermap/main.cpp51
-rw-r--r--examples/widgets/charactermap/mainwindow.cpp195
-rw-r--r--examples/widgets/charactermap/mainwindow.h83
-rw-r--r--examples/widgets/codeeditor/codeeditor.cpp170
-rw-r--r--examples/widgets/codeeditor/codeeditor.h105
-rw-r--r--examples/widgets/codeeditor/codeeditor.pro9
-rw-r--r--examples/widgets/codeeditor/main.cpp55
-rw-r--r--examples/widgets/digitalclock/digitalclock.cpp72
-rw-r--r--examples/widgets/digitalclock/digitalclock.h59
-rw-r--r--examples/widgets/digitalclock/digitalclock.pro11
-rw-r--r--examples/widgets/digitalclock/main.cpp51
-rw-r--r--examples/widgets/groupbox/groupbox.pro11
-rw-r--r--examples/widgets/groupbox/main.cpp51
-rw-r--r--examples/widgets/groupbox/window.cpp189
-rw-r--r--examples/widgets/groupbox/window.h66
-rw-r--r--examples/widgets/icons/iconpreviewarea.cpp141
-rw-r--r--examples/widgets/icons/iconpreviewarea.h77
-rw-r--r--examples/widgets/icons/icons.pro27
-rw-r--r--examples/widgets/icons/iconsizespinbox.cpp70
-rw-r--r--examples/widgets/icons/iconsizespinbox.h59
-rw-r--r--examples/widgets/icons/imagedelegate.cpp105
-rw-r--r--examples/widgets/icons/imagedelegate.h68
-rw-r--r--examples/widgets/icons/images/designer.pngbin0 -> 4205 bytes
-rw-r--r--examples/widgets/icons/images/find_disabled.pngbin0 -> 501 bytes
-rw-r--r--examples/widgets/icons/images/find_normal.pngbin0 -> 838 bytes
-rw-r--r--examples/widgets/icons/images/monkey_off_128x128.pngbin0 -> 7045 bytes
-rw-r--r--examples/widgets/icons/images/monkey_off_16x16.pngbin0 -> 683 bytes
-rw-r--r--examples/widgets/icons/images/monkey_off_32x32.pngbin0 -> 1609 bytes
-rw-r--r--examples/widgets/icons/images/monkey_off_64x64.pngbin0 -> 3533 bytes
-rw-r--r--examples/widgets/icons/images/monkey_on_128x128.pngbin0 -> 6909 bytes
-rw-r--r--examples/widgets/icons/images/monkey_on_16x16.pngbin0 -> 681 bytes
-rw-r--r--examples/widgets/icons/images/monkey_on_32x32.pngbin0 -> 1577 bytes
-rw-r--r--examples/widgets/icons/images/monkey_on_64x64.pngbin0 -> 3479 bytes
-rw-r--r--examples/widgets/icons/images/qt_extended_16x16.pngbin0 -> 834 bytes
-rw-r--r--examples/widgets/icons/images/qt_extended_32x32.pngbin0 -> 1892 bytes
-rw-r--r--examples/widgets/icons/images/qt_extended_48x48.pngbin0 -> 3672 bytes
-rw-r--r--examples/widgets/icons/main.cpp51
-rw-r--r--examples/widgets/icons/mainwindow.cpp442
-rw-r--r--examples/widgets/icons/mainwindow.h116
-rw-r--r--examples/widgets/imageviewer/imageviewer.cpp277
-rw-r--r--examples/widgets/imageviewer/imageviewer.h103
-rw-r--r--examples/widgets/imageviewer/imageviewer.pro15
-rw-r--r--examples/widgets/imageviewer/main.cpp51
-rw-r--r--examples/widgets/lineedits/lineedits.pro14
-rw-r--r--examples/widgets/lineedits/main.cpp51
-rw-r--r--examples/widgets/lineedits/window.cpp256
-rw-r--r--examples/widgets/lineedits/window.h75
-rw-r--r--examples/widgets/movie/animation.mngbin0 -> 5464 bytes
-rw-r--r--examples/widgets/movie/main.cpp51
-rw-r--r--examples/widgets/movie/movie.pro19
-rw-r--r--examples/widgets/movie/movieplayer.cpp210
-rw-r--r--examples/widgets/movie/movieplayer.h96
-rw-r--r--examples/widgets/scribble/main.cpp51
-rw-r--r--examples/widgets/scribble/mainwindow.cpp250
-rw-r--r--examples/widgets/scribble/mainwindow.h92
-rw-r--r--examples/widgets/scribble/scribble.pro13
-rw-r--r--examples/widgets/scribble/scribblearea.cpp215
-rw-r--r--examples/widgets/scribble/scribblearea.h90
-rw-r--r--examples/widgets/shapedclock/main.cpp51
-rw-r--r--examples/widgets/shapedclock/shapedclock.cpp158
-rw-r--r--examples/widgets/shapedclock/shapedclock.h66
-rw-r--r--examples/widgets/shapedclock/shapedclock.pro14
-rw-r--r--examples/widgets/sliders/main.cpp51
-rw-r--r--examples/widgets/sliders/sliders.pro13
-rw-r--r--examples/widgets/sliders/slidersgroup.cpp132
-rw-r--r--examples/widgets/sliders/slidersgroup.h78
-rw-r--r--examples/widgets/sliders/window.cpp145
-rw-r--r--examples/widgets/sliders/window.h84
-rw-r--r--examples/widgets/softkeys/main.cpp50
-rw-r--r--examples/widgets/softkeys/softkeys.cpp188
-rw-r--r--examples/widgets/softkeys/softkeys.h88
-rw-r--r--examples/widgets/softkeys/softkeys.pro15
-rw-r--r--examples/widgets/spinboxes/main.cpp51
-rw-r--r--examples/widgets/spinboxes/spinboxes.pro11
-rw-r--r--examples/widgets/spinboxes/window.cpp251
-rw-r--r--examples/widgets/spinboxes/window.h81
-rw-r--r--examples/widgets/styles/images/woodbackground.pngbin0 -> 7691 bytes
-rw-r--r--examples/widgets/styles/images/woodbutton.pngbin0 -> 7689 bytes
-rw-r--r--examples/widgets/styles/main.cpp53
-rw-r--r--examples/widgets/styles/norwegianwoodstyle.cpp330
-rw-r--r--examples/widgets/styles/norwegianwoodstyle.h78
-rw-r--r--examples/widgets/styles/styles.pro16
-rw-r--r--examples/widgets/styles/styles.qrc6
-rw-r--r--examples/widgets/styles/widgetgallery.cpp275
-rw-r--r--examples/widgets/styles/widgetgallery.h121
-rw-r--r--examples/widgets/stylesheet/images/checkbox_checked.pngbin0 -> 263 bytes
-rw-r--r--examples/widgets/stylesheet/images/checkbox_checked_hover.pngbin0 -> 266 bytes
-rw-r--r--examples/widgets/stylesheet/images/checkbox_checked_pressed.pngbin0 -> 425 bytes
-rw-r--r--examples/widgets/stylesheet/images/checkbox_unchecked.pngbin0 -> 159 bytes
-rw-r--r--examples/widgets/stylesheet/images/checkbox_unchecked_hover.pngbin0 -> 159 bytes
-rw-r--r--examples/widgets/stylesheet/images/checkbox_unchecked_pressed.pngbin0 -> 320 bytes
-rw-r--r--examples/widgets/stylesheet/images/down_arrow.pngbin0 -> 175 bytes
-rw-r--r--examples/widgets/stylesheet/images/down_arrow_disabled.pngbin0 -> 174 bytes
-rw-r--r--examples/widgets/stylesheet/images/frame.pngbin0 -> 253 bytes
-rw-r--r--examples/widgets/stylesheet/images/pagefold.pngbin0 -> 1545 bytes
-rw-r--r--examples/widgets/stylesheet/images/pushbutton.pngbin0 -> 533 bytes
-rw-r--r--examples/widgets/stylesheet/images/pushbutton_hover.pngbin0 -> 525 bytes
-rw-r--r--examples/widgets/stylesheet/images/pushbutton_pressed.pngbin0 -> 513 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_checked.pngbin0 -> 355 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_checked_hover.pngbin0 -> 532 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_checked_pressed.pngbin0 -> 599 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_unchecked.pngbin0 -> 240 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_unchecked_hover.pngbin0 -> 492 bytes
-rw-r--r--examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.pngbin0 -> 556 bytes
-rw-r--r--examples/widgets/stylesheet/images/sizegrip.pngbin0 -> 129 bytes
-rw-r--r--examples/widgets/stylesheet/images/spindown.pngbin0 -> 276 bytes
-rw-r--r--examples/widgets/stylesheet/images/spindown_hover.pngbin0 -> 268 bytes
-rw-r--r--examples/widgets/stylesheet/images/spindown_off.pngbin0 -> 249 bytes
-rw-r--r--examples/widgets/stylesheet/images/spindown_pressed.pngbin0 -> 264 bytes
-rw-r--r--examples/widgets/stylesheet/images/spinup.pngbin0 -> 283 bytes
-rw-r--r--examples/widgets/stylesheet/images/spinup_hover.pngbin0 -> 277 bytes
-rw-r--r--examples/widgets/stylesheet/images/spinup_off.pngbin0 -> 274 bytes
-rw-r--r--examples/widgets/stylesheet/images/spinup_pressed.pngbin0 -> 277 bytes
-rw-r--r--examples/widgets/stylesheet/images/up_arrow.pngbin0 -> 197 bytes
-rw-r--r--examples/widgets/stylesheet/images/up_arrow_disabled.pngbin0 -> 172 bytes
-rw-r--r--examples/widgets/stylesheet/layouts/default.ui329
-rw-r--r--examples/widgets/stylesheet/layouts/pagefold.ui349
-rw-r--r--examples/widgets/stylesheet/main.cpp53
-rw-r--r--examples/widgets/stylesheet/mainwindow.cpp74
-rw-r--r--examples/widgets/stylesheet/mainwindow.h66
-rw-r--r--examples/widgets/stylesheet/mainwindow.ui356
-rw-r--r--examples/widgets/stylesheet/qss/coffee.qss112
-rw-r--r--examples/widgets/stylesheet/qss/default.qss1
-rw-r--r--examples/widgets/stylesheet/qss/pagefold.qss299
-rw-r--r--examples/widgets/stylesheet/stylesheet.pro16
-rw-r--r--examples/widgets/stylesheet/stylesheet.qrc39
-rw-r--r--examples/widgets/stylesheet/stylesheeteditor.cpp93
-rw-r--r--examples/widgets/stylesheet/stylesheeteditor.h67
-rw-r--r--examples/widgets/stylesheet/stylesheeteditor.ui171
-rw-r--r--examples/widgets/tablet/main.cpp60
-rw-r--r--examples/widgets/tablet/mainwindow.cpp274
-rw-r--r--examples/widgets/tablet/mainwindow.h113
-rw-r--r--examples/widgets/tablet/tablet.pro15
-rw-r--r--examples/widgets/tablet/tabletapplication.cpp56
-rw-r--r--examples/widgets/tablet/tabletapplication.h66
-rw-r--r--examples/widgets/tablet/tabletcanvas.cpp275
-rw-r--r--examples/widgets/tablet/tabletcanvas.h114
-rw-r--r--examples/widgets/tetrix/main.cpp54
-rw-r--r--examples/widgets/tetrix/tetrix.pro18
-rw-r--r--examples/widgets/tetrix/tetrixboard.cpp408
-rw-r--r--examples/widgets/tetrix/tetrixboard.h116
-rw-r--r--examples/widgets/tetrix/tetrixpiece.cpp145
-rw-r--r--examples/widgets/tetrix/tetrixpiece.h75
-rw-r--r--examples/widgets/tetrix/tetrixwindow.cpp115
-rw-r--r--examples/widgets/tetrix/tetrixwindow.h76
-rw-r--r--examples/widgets/tooltips/images/circle.pngbin0 -> 165 bytes
-rw-r--r--examples/widgets/tooltips/images/square.pngbin0 -> 94 bytes
-rw-r--r--examples/widgets/tooltips/images/triangle.pngbin0 -> 170 bytes
-rw-r--r--examples/widgets/tooltips/main.cpp54
-rw-r--r--examples/widgets/tooltips/shapeitem.cpp99
-rw-r--r--examples/widgets/tooltips/shapeitem.h70
-rw-r--r--examples/widgets/tooltips/sortingbox.cpp301
-rw-r--r--examples/widgets/tooltips/sortingbox.h106
-rw-r--r--examples/widgets/tooltips/tooltips.pro14
-rw-r--r--examples/widgets/tooltips/tooltips.qrc7
-rw-r--r--examples/widgets/validators/ledoff.pngbin0 -> 562 bytes
-rw-r--r--examples/widgets/validators/ledon.pngbin0 -> 486 bytes
-rw-r--r--examples/widgets/validators/ledwidget.cpp62
-rw-r--r--examples/widgets/validators/ledwidget.h64
-rw-r--r--examples/widgets/validators/localeselector.cpp312
-rw-r--r--examples/widgets/validators/localeselector.h60
-rw-r--r--examples/widgets/validators/main.cpp136
-rw-r--r--examples/widgets/validators/validators.pro23
-rw-r--r--examples/widgets/validators/validators.qrc6
-rw-r--r--examples/widgets/validators/validators.ui468
-rw-r--r--examples/widgets/widgets.pro43
-rw-r--r--examples/widgets/wiggly/dialog.cpp80
-rw-r--r--examples/widgets/wiggly/dialog.h56
-rw-r--r--examples/widgets/wiggly/main.cpp57
-rw-r--r--examples/widgets/wiggly/wiggly.pro16
-rw-r--r--examples/widgets/wiggly/wigglywidget.cpp100
-rw-r--r--examples/widgets/wiggly/wigglywidget.h69
-rw-r--r--examples/widgets/windowflags/controllerwindow.cpp220
-rw-r--r--examples/widgets/windowflags/controllerwindow.h104
-rw-r--r--examples/widgets/windowflags/main.cpp51
-rw-r--r--examples/widgets/windowflags/previewwindow.cpp118
-rw-r--r--examples/widgets/windowflags/previewwindow.h67
-rw-r--r--examples/widgets/windowflags/windowflags.pro13
-rw-r--r--examples/xml/README40
-rw-r--r--examples/xml/dombookmarks/dombookmarks.pro20
-rw-r--r--examples/xml/dombookmarks/frank.xbel230
-rw-r--r--examples/xml/dombookmarks/jennifer.xbel93
-rw-r--r--examples/xml/dombookmarks/main.cpp52
-rw-r--r--examples/xml/dombookmarks/mainwindow.cpp145
-rw-r--r--examples/xml/dombookmarks/mainwindow.h75
-rw-r--r--examples/xml/dombookmarks/xbeltree.cpp186
-rw-r--r--examples/xml/dombookmarks/xbeltree.h74
-rw-r--r--examples/xml/htmlinfo/apache_org.html281
-rw-r--r--examples/xml/htmlinfo/htmlinfo.pro19
-rw-r--r--examples/xml/htmlinfo/main.cpp118
-rw-r--r--examples/xml/htmlinfo/nokia_com.html215
-rw-r--r--examples/xml/htmlinfo/simpleexample.html11
-rw-r--r--examples/xml/htmlinfo/trolltech_com.html955
-rw-r--r--examples/xml/htmlinfo/w3c_org.html507
-rw-r--r--examples/xml/htmlinfo/youtube_com.html1585
-rw-r--r--examples/xml/rsslisting/main.cpp63
-rw-r--r--examples/xml/rsslisting/rsslisting.cpp247
-rw-r--r--examples/xml/rsslisting/rsslisting.h90
-rw-r--r--examples/xml/rsslisting/rsslisting.pro12
-rw-r--r--examples/xml/saxbookmarks/frank.xbel230
-rw-r--r--examples/xml/saxbookmarks/jennifer.xbel93
-rw-r--r--examples/xml/saxbookmarks/main.cpp56
-rw-r--r--examples/xml/saxbookmarks/mainwindow.cpp169
-rw-r--r--examples/xml/saxbookmarks/mainwindow.h77
-rw-r--r--examples/xml/saxbookmarks/saxbookmarks.pro28
-rw-r--r--examples/xml/saxbookmarks/xbelgenerator.cpp114
-rw-r--r--examples/xml/saxbookmarks/xbelgenerator.h68
-rw-r--r--examples/xml/saxbookmarks/xbelhandler.cpp146
-rw-r--r--examples/xml/saxbookmarks/xbelhandler.h78
-rw-r--r--examples/xml/streambookmarks/frank.xbel230
-rw-r--r--examples/xml/streambookmarks/jennifer.xbel93
-rw-r--r--examples/xml/streambookmarks/main.cpp54
-rw-r--r--examples/xml/streambookmarks/mainwindow.cpp174
-rw-r--r--examples/xml/streambookmarks/mainwindow.h79
-rw-r--r--examples/xml/streambookmarks/streambookmarks.pro16
-rw-r--r--examples/xml/streambookmarks/xbelreader.cpp175
-rw-r--r--examples/xml/streambookmarks/xbelreader.h83
-rw-r--r--examples/xml/streambookmarks/xbelwriter.cpp92
-rw-r--r--examples/xml/streambookmarks/xbelwriter.h65
-rw-r--r--examples/xml/xml.pro20
-rw-r--r--examples/xml/xmlstreamlint/main.cpp127
-rw-r--r--examples/xml/xmlstreamlint/xmlstreamlint.pro12
1874 files changed, 138881 insertions, 0 deletions
diff --git a/examples/README b/examples/README
new file mode 100644
index 0000000000..10e14ceef4
--- /dev/null
+++ b/examples/README
@@ -0,0 +1,39 @@
+Qt is supplied with a number of example applications and demonstrations that
+have been written to provide developers with examples of the Qt API in use,
+highlight good programming practice, and showcase features found in each of
+Qt's core technologies.
+
+The example and demo launcher can be used to explore the different categories
+available. It provides an overview of each example, lets you view the
+documentation in Qt Assistant, and is able to launch examples and demos.
+
+Documentation for examples can be found in the Tutorials and Examples section
+of the Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/animation/README b/examples/animation/README
new file mode 100644
index 0000000000..6a892f8655
--- /dev/null
+++ b/examples/animation/README
@@ -0,0 +1,38 @@
+The animation framework aims to provide an easy way for creating animated and
+smooth GUI's. By animating Qt properties, the framework provides great freedom
+for animating widgets and other QObjects. The framework can also be used with
+the Graphics View framework.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/animation/animatedtiles/animatedtiles.pro b/examples/animation/animatedtiles/animatedtiles.pro
new file mode 100644
index 0000000000..66a54edc05
--- /dev/null
+++ b/examples/animation/animatedtiles/animatedtiles.pro
@@ -0,0 +1,13 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000D7D1
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/animatedtiles/animatedtiles.qrc b/examples/animation/animatedtiles/animatedtiles.qrc
new file mode 100644
index 0000000000..c43a979723
--- /dev/null
+++ b/examples/animation/animatedtiles/animatedtiles.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/Time-For-Lunch-2.jpg</file>
+ <file>images/centered.png</file>
+ <file>images/ellipse.png</file>
+ <file>images/figure8.png</file>
+ <file>images/kinetic.png</file>
+ <file>images/random.png</file>
+ <file>images/tile.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg
new file mode 100644
index 0000000000..c57a555490
--- /dev/null
+++ b/examples/animation/animatedtiles/images/Time-For-Lunch-2.jpg
Binary files differ
diff --git a/examples/animation/animatedtiles/images/centered.png b/examples/animation/animatedtiles/images/centered.png
new file mode 100644
index 0000000000..e416156a0e
--- /dev/null
+++ b/examples/animation/animatedtiles/images/centered.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/ellipse.png b/examples/animation/animatedtiles/images/ellipse.png
new file mode 100644
index 0000000000..2c3ba881c5
--- /dev/null
+++ b/examples/animation/animatedtiles/images/ellipse.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/figure8.png b/examples/animation/animatedtiles/images/figure8.png
new file mode 100644
index 0000000000..6b058041c4
--- /dev/null
+++ b/examples/animation/animatedtiles/images/figure8.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/kinetic.png b/examples/animation/animatedtiles/images/kinetic.png
new file mode 100644
index 0000000000..55cfa5515f
--- /dev/null
+++ b/examples/animation/animatedtiles/images/kinetic.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/random.png b/examples/animation/animatedtiles/images/random.png
new file mode 100644
index 0000000000..415d96f856
--- /dev/null
+++ b/examples/animation/animatedtiles/images/random.png
Binary files differ
diff --git a/examples/animation/animatedtiles/images/tile.png b/examples/animation/animatedtiles/images/tile.png
new file mode 100644
index 0000000000..c8f39d8d40
--- /dev/null
+++ b/examples/animation/animatedtiles/images/tile.png
Binary files differ
diff --git a/examples/animation/animatedtiles/main.cpp b/examples/animation/animatedtiles/main.cpp
new file mode 100644
index 0000000000..1badb4f3ef
--- /dev/null
+++ b/examples/animation/animatedtiles/main.cpp
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+#include <QtCore/qstate.h>
+
+class Pixmap : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ Pixmap(const QPixmap &pix)
+ : QObject(), QGraphicsPixmapItem(pix)
+ {
+ setCacheMode(DeviceCoordinateCache);
+ }
+};
+
+class Button : public QGraphicsWidget
+{
+ Q_OBJECT
+public:
+ Button(const QPixmap &pixmap, QGraphicsItem *parent = 0)
+ : QGraphicsWidget(parent), _pix(pixmap)
+ {
+ setAcceptHoverEvents(true);
+ setCacheMode(DeviceCoordinateCache);
+ }
+
+ QRectF boundingRect() const
+ {
+ return QRectF(-65, -65, 130, 130);
+ }
+
+ QPainterPath shape() const
+ {
+ QPainterPath path;
+ path.addEllipse(boundingRect());
+ return path;
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+ {
+ bool down = option->state & QStyle::State_Sunken;
+ QRectF r = boundingRect();
+ QLinearGradient grad(r.topLeft(), r.bottomRight());
+ grad.setColorAt(down ? 1 : 0, option->state & QStyle::State_MouseOver ? Qt::white : Qt::lightGray);
+ grad.setColorAt(down ? 0 : 1, Qt::darkGray);
+ painter->setPen(Qt::darkGray);
+ painter->setBrush(grad);
+ painter->drawEllipse(r);
+ QLinearGradient grad2(r.topLeft(), r.bottomRight());
+ grad.setColorAt(down ? 1 : 0, Qt::darkGray);
+ grad.setColorAt(down ? 0 : 1, Qt::lightGray);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(grad);
+ if (down)
+ painter->translate(2, 2);
+ painter->drawEllipse(r.adjusted(5, 5, -5, -5));
+ painter->drawPixmap(-_pix.width()/2, -_pix.height()/2, _pix);
+ }
+
+signals:
+ void pressed();
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *)
+ {
+ emit pressed();
+ update();
+ }
+
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ {
+ update();
+ }
+
+private:
+ QPixmap _pix;
+};
+
+class View : public QGraphicsView
+{
+public:
+ View(QGraphicsScene *scene) : QGraphicsView(scene) { }
+
+protected:
+ void resizeEvent(QResizeEvent *event)
+ {
+ QGraphicsView::resizeEvent(event);
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+ }
+};
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(animatedtiles);
+
+ QApplication app(argc, argv);
+
+ QPixmap kineticPix(":/images/kinetic.png");
+ QPixmap bgPix(":/images/Time-For-Lunch-2.jpg");
+
+ QGraphicsScene scene(-350, -350, 700, 700);
+
+ QList<Pixmap *> items;
+ for (int i = 0; i < 64; ++i) {
+ Pixmap *item = new Pixmap(kineticPix);
+ item->setOffset(-kineticPix.width()/2, -kineticPix.height()/2);
+ item->setZValue(i);
+ items << item;
+ scene.addItem(item);
+ }
+
+ // Buttons
+ QGraphicsItem *buttonParent = new QGraphicsRectItem;
+ Button *ellipseButton = new Button(QPixmap(":/images/ellipse.png"), buttonParent);
+ Button *figure8Button = new Button(QPixmap(":/images/figure8.png"), buttonParent);
+ Button *randomButton = new Button(QPixmap(":/images/random.png"), buttonParent);
+ Button *tiledButton = new Button(QPixmap(":/images/tile.png"), buttonParent);
+ Button *centeredButton = new Button(QPixmap(":/images/centered.png"), buttonParent);
+
+ ellipseButton->setPos(-100, -100);
+ figure8Button->setPos(100, -100);
+ randomButton->setPos(0, 0);
+ tiledButton->setPos(-100, 100);
+ centeredButton->setPos(100, 100);
+
+ scene.addItem(buttonParent);
+ buttonParent->scale(0.75, 0.75);
+ buttonParent->setPos(200, 200);
+ buttonParent->setZValue(65);
+
+ // States
+ QState *rootState = new QState;
+ QState *ellipseState = new QState(rootState);
+ QState *figure8State = new QState(rootState);
+ QState *randomState = new QState(rootState);
+ QState *tiledState = new QState(rootState);
+ QState *centeredState = new QState(rootState);
+
+ // Values
+ for (int i = 0; i < 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/animation/animation.pro b/examples/animation/animation.pro
new file mode 100644
index 0000000000..4a9064d97e
--- /dev/null
+++ b/examples/animation/animation.pro
@@ -0,0 +1,15 @@
+TEMPLATE = \
+ subdirs
+SUBDIRS += \
+ animatedtiles \
+ appchooser \
+ easing \
+ moveblocks \
+ states \
+ stickman \
+
+# 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
diff --git a/examples/animation/appchooser/accessories-dictionary.png b/examples/animation/appchooser/accessories-dictionary.png
new file mode 100644
index 0000000000..e9bd55d918
--- /dev/null
+++ b/examples/animation/appchooser/accessories-dictionary.png
Binary files differ
diff --git a/examples/animation/appchooser/akregator.png b/examples/animation/appchooser/akregator.png
new file mode 100644
index 0000000000..a086f45ab6
--- /dev/null
+++ b/examples/animation/appchooser/akregator.png
Binary files differ
diff --git a/examples/animation/appchooser/appchooser.pro b/examples/animation/appchooser/appchooser.pro
new file mode 100644
index 0000000000..d4599db840
--- /dev/null
+++ b/examples/animation/appchooser/appchooser.pro
@@ -0,0 +1,13 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000E3F5
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/appchooser/appchooser.qrc b/examples/animation/appchooser/appchooser.qrc
new file mode 100644
index 0000000000..28a3e1c4c1
--- /dev/null
+++ b/examples/animation/appchooser/appchooser.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>accessories-dictionary.png</file>
+ <file>akregator.png</file>
+ <file>digikam.png</file>
+ <file>k3b.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/appchooser/digikam.png b/examples/animation/appchooser/digikam.png
new file mode 100644
index 0000000000..9de9fb2f80
--- /dev/null
+++ b/examples/animation/appchooser/digikam.png
Binary files differ
diff --git a/examples/animation/appchooser/k3b.png b/examples/animation/appchooser/k3b.png
new file mode 100644
index 0000000000..bbcafcfba1
--- /dev/null
+++ b/examples/animation/appchooser/k3b.png
Binary files differ
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
new file mode 100644
index 0000000000..86ec073f6e
--- /dev/null
+++ b/examples/animation/appchooser/main.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+
+class Pixmap : public QGraphicsWidget
+{
+ Q_OBJECT
+
+public:
+ Pixmap(const QPixmap &pix, QGraphicsItem *parent = 0)
+ : QGraphicsWidget(parent), orig(pix), p(pix)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ painter->drawPixmap(QPointF(), p);
+ }
+
+ virtual void mousePressEvent(QGraphicsSceneMouseEvent * )
+ {
+ emit clicked();
+ }
+
+ virtual void setGeometry(const QRectF &rect)
+ {
+ QGraphicsWidget::setGeometry(rect);
+
+ if (rect.size().width() > orig.size().width())
+ p = orig.scaled(rect.size().toSize());
+ else
+ p = orig;
+ }
+
+Q_SIGNALS:
+ void clicked();
+
+private:
+ QPixmap orig;
+ QPixmap p;
+};
+
+void createStates(const QObjectList &objects,
+ const QRect &selectedRect, QState *parent)
+{
+ for (int i = 0; i < objects.size(); ++i) {
+ QState *state = new QState(parent);
+ state->assignProperty(objects.at(i), "geometry", selectedRect);
+ parent->addTransition(objects.at(i), SIGNAL(clicked()), state);
+ }
+}
+
+void createAnimations(const QObjectList &objects, QStateMachine *machine)
+{
+ for (int i=0; i<objects.size(); ++i)
+ machine->addDefaultAnimation(new QPropertyAnimation(objects.at(i), "geometry"));
+}
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(appchooser);
+
+ QApplication app(argc, argv);
+
+ Pixmap *p1 = new Pixmap(QPixmap(":/digikam.png"));
+ Pixmap *p2 = new Pixmap(QPixmap(":/akregator.png"));
+ Pixmap *p3 = new Pixmap(QPixmap(":/accessories-dictionary.png"));
+ Pixmap *p4 = new Pixmap(QPixmap(":/k3b.png"));
+
+ p1->setObjectName("p1");
+ p2->setObjectName("p2");
+ p3->setObjectName("p3");
+ p4->setObjectName("p4");
+
+ p1->setGeometry(QRectF(0.0, 0.0, 64.0, 64.0));
+ p2->setGeometry(QRectF(236.0, 0.0, 64.0, 64.0));
+ p3->setGeometry(QRectF(236.0, 236.0, 64.0, 64.0));
+ p4->setGeometry(QRectF(0.0, 236.0, 64.0, 64.0));
+
+ QGraphicsScene scene(0, 0, 300, 300);
+ scene.setBackgroundBrush(Qt::white);
+ scene.addItem(p1);
+ scene.addItem(p2);
+ scene.addItem(p3);
+ scene.addItem(p4);
+
+ QGraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QState *group = new QState(&machine);
+ group->setObjectName("group");
+ QRect selectedRect(86, 86, 128, 128);
+
+ QState *idleState = new QState(group);
+ group->setInitialState(idleState);
+
+ QObjectList objects;
+ objects << p1 << p2 << p3 << p4;
+ createStates(objects, selectedRect, group);
+ createAnimations(objects, &machine);
+
+ machine.setInitialState(group);
+ machine.start();
+
+ window.resize(300, 300);
+ window.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/easing/animation.h b/examples/animation/easing/animation.h
new file mode 100644
index 0000000000..f0aef6560b
--- /dev/null
+++ b/examples/animation/easing/animation.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+#include <QtCore/qpropertyanimation.h>
+
+class Animation : public QPropertyAnimation {
+public:
+ enum PathType {
+ LinearPath,
+ CirclePath,
+ NPathTypes
+ };
+ Animation(QObject *target, const QByteArray &prop)
+ : QPropertyAnimation(target, prop)
+ {
+ setPathType(LinearPath);
+ }
+
+ void setPathType(PathType pathType)
+ {
+ if (pathType >= NPathTypes)
+ qWarning("Unknown pathType %d", pathType);
+
+ m_pathType = pathType;
+ m_path = QPainterPath();
+ }
+
+ void updateCurrentTime(int 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/animation/easing/easing.pro b/examples/animation/easing/easing.pro
new file mode 100644
index 0000000000..4715f2c826
--- /dev/null
+++ b/examples/animation/easing/easing.pro
@@ -0,0 +1,19 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000E3F6
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/easing/easing.qrc b/examples/animation/easing/easing.qrc
new file mode 100644
index 0000000000..7e112d3a9d
--- /dev/null
+++ b/examples/animation/easing/easing.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/qt-logo.png</file>
+ </qresource>
+ </RCC> \ No newline at end of file
diff --git a/examples/animation/easing/form.ui b/examples/animation/easing/form.ui
new file mode 100644
index 0000000000..b60ade86a4
--- /dev/null
+++ b/examples/animation/easing/form.ui
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>545</width>
+ <height>471</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Easing curves</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QListWidget" name="easingCurvePicker">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="movement">
+ <enum>QListView::Static</enum>
+ </property>
+ <property name="isWrapping" stdset="0">
+ <bool>false</bool>
+ </property>
+ <property name="viewMode">
+ <enum>QListView::IconMode</enum>
+ </property>
+ <property name="selectionRectVisible">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Path type</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="lineRadio">
+ <property name="text">
+ <string>Line</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="circleRadio">
+ <property name="text">
+ <string>Circle</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Properties</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Period</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="periodSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Amplitude</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="amplitudeSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Overshoot</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="overshootSpinBox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <double>-1.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.100000000000000</double>
+ </property>
+ <property name="value">
+ <double>-1.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="1">
+ <widget class="QGraphicsView" name="graphicsView">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <buttongroups>
+ <buttongroup name="buttonGroup"/>
+ </buttongroups>
+</ui>
diff --git a/examples/animation/easing/images/qt-logo.png b/examples/animation/easing/images/qt-logo.png
new file mode 100644
index 0000000000..14ddf2a028
--- /dev/null
+++ b/examples/animation/easing/images/qt-logo.png
Binary files differ
diff --git a/examples/animation/easing/main.cpp b/examples/animation/easing/main.cpp
new file mode 100644
index 0000000000..def1db27de
--- /dev/null
+++ b/examples/animation/easing/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+#include "window.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(easing);
+ QApplication app(argc, argv);
+ Window w;
+ w.resize(400, 400);
+ w.show();
+ return app.exec();
+}
diff --git a/examples/animation/easing/window.cpp b/examples/animation/easing/window.cpp
new file mode 100644
index 0000000000..b466cec3d0
--- /dev/null
+++ b/examples/animation/easing/window.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/easing/window.h b/examples/animation/easing/window.h
new file mode 100644
index 0000000000..bbdf14e0dc
--- /dev/null
+++ b/examples/animation/easing/window.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+#include "ui_form.h"
+#include "animation.h"
+
+class PixmapItem : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QPointF pos READ pos WRITE setPos)
+public:
+ PixmapItem(const QPixmap &pix) : QGraphicsPixmapItem(pix)
+ {
+ }
+};
+
+class Window : public QWidget {
+ Q_OBJECT
+public:
+ Window(QWidget *parent = 0);
+private slots:
+ void curveChanged(int row);
+ void pathChanged(int index);
+ void periodChanged(double);
+ void amplitudeChanged(double);
+ void overshootChanged(double);
+
+private:
+ void createCurveIcons();
+ void startAnimation();
+
+ Ui::Form m_ui;
+ QGraphicsScene m_scene;
+ PixmapItem *m_item;
+ Animation *m_anim;
+ QSize m_iconSize;
+
+
+};
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
new file mode 100644
index 0000000000..3194c1b623
--- /dev/null
+++ b/examples/animation/moveblocks/main.cpp
@@ -0,0 +1,319 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+//![15]
+class StateSwitchEvent: public QEvent
+{
+public:
+ StateSwitchEvent()
+ : QEvent(Type(StateSwitchType))
+ {
+ }
+
+ StateSwitchEvent(int rand)
+ : QEvent(Type(StateSwitchType)),
+ m_rand(rand)
+ {
+ }
+
+ enum { StateSwitchType = QEvent::User + 256 };
+
+ int rand() const { return m_rand; }
+
+private:
+ int m_rand;
+};
+//![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]
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+#if 0
+ QWidget window;
+ QPalette palette;
+ palette.setBrush(QPalette::Window, Qt::black);
+ window.setPalette(palette);
+ QPushButton *button1 = new QPushButton("A", &window);
+ QPushButton *button2 = new QPushButton("B", &window);
+ QPushButton *button3 = new QPushButton("C", &window);
+ QPushButton *button4 = new QPushButton("D", &window);
+
+ button1->setObjectName("button1");
+ button2->setObjectName("button2");
+ button3->setObjectName("button3");
+ button4->setObjectName("button4");
+#else
+//![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]
+ QGraphicsView window(&scene);
+ window.setFrameStyle(0);
+ window.setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ window.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+#endif
+//![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/animation/moveblocks/moveblocks.pro b/examples/animation/moveblocks/moveblocks.pro
new file mode 100644
index 0000000000..6451b67886
--- /dev/null
+++ b/examples/animation/moveblocks/moveblocks.pro
@@ -0,0 +1,12 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000E3F7
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/states/accessories-dictionary.png b/examples/animation/states/accessories-dictionary.png
new file mode 100644
index 0000000000..e9bd55d918
--- /dev/null
+++ b/examples/animation/states/accessories-dictionary.png
Binary files differ
diff --git a/examples/animation/states/akregator.png b/examples/animation/states/akregator.png
new file mode 100644
index 0000000000..a086f45ab6
--- /dev/null
+++ b/examples/animation/states/akregator.png
Binary files differ
diff --git a/examples/animation/states/digikam.png b/examples/animation/states/digikam.png
new file mode 100644
index 0000000000..9de9fb2f80
--- /dev/null
+++ b/examples/animation/states/digikam.png
Binary files differ
diff --git a/examples/animation/states/help-browser.png b/examples/animation/states/help-browser.png
new file mode 100644
index 0000000000..db92faa4e7
--- /dev/null
+++ b/examples/animation/states/help-browser.png
Binary files differ
diff --git a/examples/animation/states/k3b.png b/examples/animation/states/k3b.png
new file mode 100644
index 0000000000..bbcafcfba1
--- /dev/null
+++ b/examples/animation/states/k3b.png
Binary files differ
diff --git a/examples/animation/states/kchart.png b/examples/animation/states/kchart.png
new file mode 100644
index 0000000000..1dd115be87
--- /dev/null
+++ b/examples/animation/states/kchart.png
Binary files differ
diff --git a/examples/animation/states/main.cpp b/examples/animation/states/main.cpp
new file mode 100644
index 0000000000..1565489069
--- /dev/null
+++ b/examples/animation/states/main.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+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;
+};
+
+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, 185));
+ state1->assignProperty(p2, "pos", QPointF(168, 185));
+ state1->assignProperty(p3, "pos", QPointF(268, 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();
+
+ QGraphicsView view(&scene);
+ view.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/animation/states/states.pro b/examples/animation/states/states.pro
new file mode 100644
index 0000000000..dd5e09f365
--- /dev/null
+++ b/examples/animation/states/states.pro
@@ -0,0 +1,13 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000E3F8
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/states/states.qrc b/examples/animation/states/states.qrc
new file mode 100644
index 0000000000..60ab3f7a60
--- /dev/null
+++ b/examples/animation/states/states.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>accessories-dictionary.png</file>
+ <file>akregator.png</file>
+ <file>digikam.png</file>
+ <file>help-browser.png</file>
+ <file>k3b.png</file>
+ <file>kchart.png</file>
+</qresource>
+</RCC>
diff --git a/examples/animation/stickman/animation.cpp b/examples/animation/stickman/animation.cpp
new file mode 100644
index 0000000000..af7144be2c
--- /dev/null
+++ b/examples/animation/stickman/animation.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QIODevice>
+#include <QDataStream>
+
+class Frame
+{
+public:
+ Frame() {
+ }
+
+ int nodeCount() const
+ {
+ return m_nodePositions.size();
+ }
+
+ void setNodeCount(int nodeCount)
+ {
+ while (nodeCount > m_nodePositions.size())
+ m_nodePositions.append(QPointF());
+
+ while (nodeCount < m_nodePositions.size())
+ m_nodePositions.removeLast();
+ }
+
+ QPointF nodePos(int idx) const
+ {
+ return m_nodePositions.at(idx);
+ }
+
+ void setNodePos(int idx, const QPointF &pos)
+ {
+ m_nodePositions[idx] = pos;
+ }
+
+private:
+ QList<QPointF> m_nodePositions;
+};
+
+Animation::Animation()
+{
+ m_currentFrame = 0;
+ m_frames.append(new Frame);
+}
+
+Animation::~Animation()
+{
+ qDeleteAll(m_frames);
+}
+
+void Animation::setTotalFrames(int totalFrames)
+{
+ while (m_frames.size() < totalFrames)
+ m_frames.append(new Frame);
+
+ while (totalFrames < m_frames.size())
+ delete m_frames.takeLast();
+}
+
+int Animation::totalFrames() const
+{
+ return m_frames.size();
+}
+
+void Animation::setCurrentFrame(int currentFrame)
+{
+ m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0);
+}
+
+int Animation::currentFrame() const
+{
+ return m_currentFrame;
+}
+
+void Animation::setNodeCount(int nodeCount)
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ frame->setNodeCount(nodeCount);
+}
+
+int Animation::nodeCount() const
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ return frame->nodeCount();
+}
+
+void Animation::setNodePos(int idx, const QPointF &pos)
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ frame->setNodePos(idx, pos);
+}
+
+QPointF Animation::nodePos(int idx) const
+{
+ Frame *frame = m_frames.at(m_currentFrame);
+ return frame->nodePos(idx);
+}
+
+QString Animation::name() const
+{
+ return m_name;
+}
+
+void Animation::setName(const QString &name)
+{
+ m_name = name;
+}
+
+void Animation::save(QIODevice *device) const
+{
+ QDataStream stream(device);
+ stream << m_name;
+ stream << m_frames.size();
+ foreach (Frame *frame, m_frames) {
+ stream << frame->nodeCount();
+ for (int i=0; i<frame->nodeCount(); ++i)
+ stream << frame->nodePos(i);
+ }
+}
+
+void Animation::load(QIODevice *device)
+{
+ if (!m_frames.isEmpty())
+ qDeleteAll(m_frames);
+
+ m_frames.clear();
+
+ QDataStream stream(device);
+ stream >> m_name;
+
+ int frameCount;
+ stream >> frameCount;
+
+ for (int i=0; i<frameCount; ++i) {
+
+ int nodeCount;
+ stream >> nodeCount;
+
+ Frame *frame = new Frame;
+ frame->setNodeCount(nodeCount);
+
+ for (int j=0; j<nodeCount; ++j) {
+ QPointF pos;
+ stream >> pos;
+
+ frame->setNodePos(j, pos);
+ }
+
+ m_frames.append(frame);
+ }
+}
diff --git a/examples/animation/stickman/animation.h b/examples/animation/stickman/animation.h
new file mode 100644
index 0000000000..51edda6e63
--- /dev/null
+++ b/examples/animation/stickman/animation.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/stickman/animations/chilling b/examples/animation/stickman/animations/chilling
new file mode 100644
index 0000000000..a81fc7a18c
--- /dev/null
+++ b/examples/animation/stickman/animations/chilling
Binary files differ
diff --git a/examples/animation/stickman/animations/dancing b/examples/animation/stickman/animations/dancing
new file mode 100644
index 0000000000..462f66f89b
--- /dev/null
+++ b/examples/animation/stickman/animations/dancing
Binary files differ
diff --git a/examples/animation/stickman/animations/dead b/examples/animation/stickman/animations/dead
new file mode 100644
index 0000000000..9859b4b4cd
--- /dev/null
+++ b/examples/animation/stickman/animations/dead
Binary files differ
diff --git a/examples/animation/stickman/animations/jumping b/examples/animation/stickman/animations/jumping
new file mode 100644
index 0000000000..12661a15f8
--- /dev/null
+++ b/examples/animation/stickman/animations/jumping
Binary files differ
diff --git a/examples/animation/stickman/graphicsview.cpp b/examples/animation/stickman/graphicsview.cpp
new file mode 100644
index 0000000000..23036efe92
--- /dev/null
+++ b/examples/animation/stickman/graphicsview.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui/QGraphicsScene>
+#include <QtGui/QGraphicsView>
+
+GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent), m_editor(0) {}
+
+void GraphicsView::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ close();
+ emit keyPressed(Qt::Key(e->key()));
+}
+
+
diff --git a/examples/animation/stickman/graphicsview.h b/examples/animation/stickman/graphicsview.h
new file mode 100644
index 0000000000..9cf87b63e6
--- /dev/null
+++ b/examples/animation/stickman/graphicsview.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui/QGraphicsView>
+
+class MainWindow;
+class GraphicsView: public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QWidget *parent = 0);
+
+protected:
+ void keyPressEvent(QKeyEvent *);
+
+signals:
+ void keyPressed(int key);
+
+private:
+ MainWindow *m_editor;
+};
+
+#endif
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
new file mode 100644
index 0000000000..4abcdc22e5
--- /dev/null
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+class KeyPressTransition: public QSignalTransition
+{
+public:
+ KeyPressTransition(GraphicsView *receiver, Qt::Key key)
+ : QSignalTransition(receiver, SIGNAL(keyPressed(int))), m_key(key)
+ {
+ }
+ KeyPressTransition(GraphicsView *receiver, Qt::Key key, QAbstractState *target)
+ : QSignalTransition(receiver, SIGNAL(keyPressed(int))), 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)
+{
+ QState *state = makeState(m_alive, fileName);
+ m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
+}
+
+QState *LifeCycle::makeState(QState *parentState, const QString &animationFileName)
+{
+ QState *topLevel = new QState(parentState);
+
+ Animation animation;
+ {
+ QFile file(animationFileName);
+ if (file.open(QIODevice::ReadOnly))
+ animation.load(&file);
+ }
+
+ const int frameCount = animation.totalFrames();
+ QState *previousState = 0;
+ for (int i=0; i<frameCount; ++i) {
+ animation.setCurrentFrame(i);
+
+//! [1]
+ QState *frameState = new QState(topLevel);
+ const int nodeCount = animation.nodeCount();
+ for (int j=0; j<nodeCount; ++j)
+ frameState->assignProperty(m_stickMan->node(j), "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/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
new file mode 100644
index 0000000000..1bf3661f6c
--- /dev/null
+++ b/examples/animation/stickman/lifecycle.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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;
+QT_END_NAMESPACE
+class GraphicsView;
+class LifeCycle
+{
+public:
+ LifeCycle(StickMan *stickMan, GraphicsView *keyEventReceiver);
+ ~LifeCycle();
+
+ void setDeathAnimation(const QString &fileName);
+ void addActivity(const QString &fileName, Qt::Key key);
+
+ void start();
+
+private:
+ QState *makeState(QState *parentState, const QString &animationFileName);
+
+ StickMan *m_stickMan;
+ QStateMachine *m_machine;
+ QAnimationGroup *m_animationGroup;
+ GraphicsView *m_keyReceiver;
+
+ QState *m_alive;
+ QState *m_dead;
+ QState *m_idle;
+};
+
+#endif
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
new file mode 100644
index 0000000000..08df766509
--- /dev/null
+++ b/examples/animation/stickman/main.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtCore>
+#include <QtGui>
+
+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);
+ view.show();
+ view.setFocus();
+
+ 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);
+
+ LifeCycle cycle(stickMan, &view);
+ cycle.setDeathAnimation(":/animations/dead");
+
+ cycle.addActivity(":/animations/jumping", Qt::Key_J);
+ cycle.addActivity(":/animations/dancing", Qt::Key_D);
+ cycle.addActivity(":/animations/chilling", Qt::Key_C);
+ cycle.start();
+
+ return app.exec();
+}
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp
new file mode 100644
index 0000000000..3077dffb12
--- /dev/null
+++ b/examples/animation/stickman/node.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/stickman/node.h b/examples/animation/stickman/node.h
new file mode 100644
index 0000000000..cefb3a81ac
--- /dev/null
+++ b/examples/animation/stickman/node.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp
new file mode 100644
index 0000000000..8b474579c2
--- /dev/null
+++ b/examples/animation/stickman/stickman.cpp
@@ -0,0 +1,337 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h
new file mode 100644
index 0000000000..eeebbef283
--- /dev/null
+++ b/examples/animation/stickman/stickman.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro
new file mode 100644
index 0000000000..a4f5aafb2d
--- /dev/null
+++ b/examples/animation/stickman/stickman.pro
@@ -0,0 +1,24 @@
+HEADERS += stickman.h \
+ animation.h \
+ node.h \
+ lifecycle.h \
+ graphicsview.h
+SOURCES += main.cpp \
+ stickman.cpp \
+ animation.cpp \
+ node.cpp \
+ lifecycle.cpp \
+ graphicsview.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
+
+symbian {
+ TARGET.UID3 = 0xA000E3F9
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/animation/stickman/stickman.qrc b/examples/animation/stickman/stickman.qrc
new file mode 100644
index 0000000000..e5d66cf2c7
--- /dev/null
+++ b/examples/animation/stickman/stickman.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>animations/chilling</file>
+ <file>animations/dancing</file>
+ <file>animations/dead</file>
+ <file>animations/jumping</file>
+</qresource>
+</RCC> \ No newline at end of file
diff --git a/examples/dbus/complexpingpong/complexping.cpp b/examples/dbus/complexpingpong/complexping.cpp
new file mode 100644
index 0000000000..4e17486439
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexping.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdio.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QFile>
+#include <QtCore/QDebug>
+#include <QtCore/QProcess>
+#include <QtDBus/QtDBus>
+
+#include "ping-common.h"
+#include "complexping.h"
+
+void Ping::start(const QString &name, const QString &oldValue, const QString &newValue)
+{
+ Q_UNUSED(oldValue);
+
+ if (name != SERVICE_NAME || newValue.isEmpty())
+ return;
+
+ // open stdin for reading
+ qstdin.open(stdin, QIODevice::ReadOnly);
+
+ // find our remote
+ iface = new QDBusInterface(SERVICE_NAME, "/", "com.trolltech.QtDBus.ComplexPong.Pong",
+ QDBusConnection::sessionBus(), this);
+ if (!iface->isValid()) {
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ QCoreApplication::instance()->quit();
+ }
+
+ connect(iface, SIGNAL(aboutToQuit()), QCoreApplication::instance(), SLOT(quit()));
+
+ while (true) {
+ printf("Ask your question: ");
+
+ QString line = QString::fromLocal8Bit(qstdin.readLine()).trimmed();
+ if (line.isEmpty()) {
+ iface->call("quit");
+ return;
+ } else if (line == "value") {
+ QVariant reply = iface->property("value");
+ if (!reply.isNull())
+ printf("value = %s\n", qPrintable(reply.toString()));
+ } else if (line.startsWith("value=")) {
+ iface->setProperty("value", line.mid(6));
+ } else {
+ QDBusReply<QDBusVariant> reply = iface->call("query", line);
+ if (reply.isValid())
+ printf("Reply was: %s\n", qPrintable(reply.value().variant().toString()));
+ }
+
+ if (iface->lastError().isValid())
+ fprintf(stderr, "Call failed: %s\n", qPrintable(iface->lastError().message()));
+ }
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
+ "To start it, run:\n"
+ "\teval `dbus-launch --auto-syntax`\n");
+ return 1;
+ }
+
+ Ping ping;
+ ping.connect(QDBusConnection::sessionBus().interface(),
+ SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+ SLOT(start(QString,QString,QString)));
+
+ QProcess pong;
+ pong.start("./complexpong");
+
+ app.exec();
+}
diff --git a/examples/dbus/complexpingpong/complexping.h b/examples/dbus/complexpingpong/complexping.h
new file mode 100644
index 0000000000..bf54e630a8
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexping.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMPLEXPING_H
+#define COMPLEXPING_H
+
+#include <QtCore/QObject>
+#include <QtCore/QFile>
+#include <QtDBus/QDBusInterface>
+
+class Ping: public QObject
+{
+ Q_OBJECT
+public slots:
+ void start(const QString &, const QString &, const QString &);
+public:
+ QFile qstdin;
+ QDBusInterface *iface;
+};
+
+#endif
diff --git a/examples/dbus/complexpingpong/complexping.pro b/examples/dbus/complexpingpong/complexping.pro
new file mode 100644
index 0000000000..ff4b9c236a
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexping.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT -= gui
+CONFIG += qdbus
+
+# Input
+HEADERS += complexping.h ping-common.h
+SOURCES += complexping.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/complexpingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/complexpingpong
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/complexpingpong/complexpingpong.pro b/examples/dbus/complexpingpong/complexpingpong.pro
new file mode 100644
index 0000000000..cd618d549d
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpingpong.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+win32:CONFIG += console
+SUBDIRS = complexping.pro complexpong.pro
diff --git a/examples/dbus/complexpingpong/complexpong.cpp b/examples/dbus/complexpingpong/complexpong.cpp
new file mode 100644
index 0000000000..f16afd3121
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpong.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QTimer>
+#include <QtDBus/QtDBus>
+
+#include "ping-common.h"
+#include "complexpong.h"
+
+// the property
+QString Pong::value() const
+{
+ return m_value;
+}
+
+void Pong::setValue(const QString &newValue)
+{
+ m_value = newValue;
+}
+
+void Pong::quit()
+{
+ QTimer::singleShot(0, QCoreApplication::instance(), SLOT(quit()));
+}
+
+QDBusVariant Pong::query(const QString &query)
+{
+ QString q = query.toLower();
+ if (q == "hello")
+ return QDBusVariant("World");
+ if (q == "ping")
+ return QDBusVariant("Pong");
+ if (q.indexOf("the answer to life, the universe and everything") != -1)
+ return QDBusVariant(42);
+ if (q.indexOf("unladen swallow") != -1) {
+ if (q.indexOf("european") != -1)
+ return QDBusVariant(11.0);
+ return QDBusVariant(QByteArray("african or european?"));
+ }
+
+ return QDBusVariant("Sorry, I don't know the answer");
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QObject obj;
+ Pong *pong = new Pong(&obj);
+ pong->connect(&app, SIGNAL(aboutToQuit()), SIGNAL(aboutToQuit()));
+ pong->setProperty("value", "initial value");
+ QDBusConnection::sessionBus().registerObject("/", &obj);
+
+ if (!QDBusConnection::sessionBus().registerService(SERVICE_NAME)) {
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ exit(1);
+ }
+
+ app.exec();
+ return 0;
+}
+
diff --git a/examples/dbus/complexpingpong/complexpong.h b/examples/dbus/complexpingpong/complexpong.h
new file mode 100644
index 0000000000..cc05972f02
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpong.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMPLEXPONG_H
+#define COMPLEXPONG_H
+
+#include <QtCore/QObject>
+#include <QtDBus/QDBusAbstractAdaptor>
+#include <QtDBus/QDBusVariant>
+
+class Pong: public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.ComplexPong.Pong")
+ Q_PROPERTY(QString value READ value WRITE setValue)
+public:
+ QString m_value;
+ QString value() const;
+ void setValue(const QString &newValue);
+
+ Pong(QObject *obj) : QDBusAbstractAdaptor(obj)
+ { }
+signals:
+ void aboutToQuit();
+public slots:
+ QDBusVariant query(const QString &query);
+ Q_NOREPLY void quit();
+};
+
+#endif
diff --git a/examples/dbus/complexpingpong/complexpong.pro b/examples/dbus/complexpingpong/complexpong.pro
new file mode 100644
index 0000000000..166293beed
--- /dev/null
+++ b/examples/dbus/complexpingpong/complexpong.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT -= gui
+CONFIG += qdbus
+
+# Input
+HEADERS += complexpong.h
+SOURCES += complexpong.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/complexpingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/complexpingpong
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/complexpingpong/ping-common.h b/examples/dbus/complexpingpong/ping-common.h
new file mode 100644
index 0000000000..532517394b
--- /dev/null
+++ b/examples/dbus/complexpingpong/ping-common.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#define SERVICE_NAME "com.trolltech.QtDBus.PingExample"
diff --git a/examples/dbus/dbus-chat/chat.cpp b/examples/dbus/dbus-chat/chat.cpp
new file mode 100644
index 0000000000..5cc12caafa
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "chat.h"
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+
+#include "chat_adaptor.h"
+#include "chat_interface.h"
+
+ChatMainWindow::ChatMainWindow()
+ : m_nickname(QLatin1String("nickname"))
+{
+ setupUi(this);
+ sendButton->setEnabled(false);
+
+ connect(messageLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(textChangedSlot(QString)));
+ connect(sendButton, SIGNAL(clicked(bool)), this, SLOT(sendClickedSlot()));
+ connect(actionChangeNickname, SIGNAL(triggered(bool)), this, SLOT(changeNickname()));
+ connect(actionAboutQt, SIGNAL(triggered(bool)), this, SLOT(aboutQt()));
+ connect(qApp, SIGNAL(lastWindowClosed()), this, SLOT(exiting()));
+
+ // add our D-Bus interface and connect to D-Bus
+ new ChatAdaptor(this);
+ QDBusConnection::sessionBus().registerObject("/", this);
+
+ com::trolltech::chat *iface;
+ iface = new com::trolltech::chat(QString(), QString(), QDBusConnection::sessionBus(), this);
+ //connect(iface, SIGNAL(message(QString,QString)), this, SLOT(messageSlot(QString,QString)));
+ QDBusConnection::sessionBus().connect(QString(), QString(), "com.trolltech.chat", "message", this, SLOT(messageSlot(QString,QString)));
+ connect(iface, SIGNAL(action(QString,QString)), this, SLOT(actionSlot(QString,QString)));
+
+ NicknameDialog dialog;
+ dialog.cancelButton->setVisible(false);
+ dialog.exec();
+ m_nickname = dialog.nickname->text().trimmed();
+ emit action(m_nickname, QLatin1String("joins the chat"));
+}
+
+ChatMainWindow::~ChatMainWindow()
+{
+}
+
+void ChatMainWindow::rebuildHistory()
+{
+ QString history = m_messages.join( QLatin1String("\n" ) );
+ chatHistory->setPlainText(history);
+}
+
+void ChatMainWindow::messageSlot(const QString &nickname, const QString &text)
+{
+ QString msg( QLatin1String("<%1> %2") );
+ msg = msg.arg(nickname, text);
+ m_messages.append(msg);
+
+ if (m_messages.count() > 100)
+ m_messages.removeFirst();
+ rebuildHistory();
+}
+
+void ChatMainWindow::actionSlot(const QString &nickname, const QString &text)
+{
+ QString msg( QLatin1String("* %1 %2") );
+ msg = msg.arg(nickname, text);
+ m_messages.append(msg);
+
+ if (m_messages.count() > 100)
+ m_messages.removeFirst();
+ rebuildHistory();
+}
+
+void ChatMainWindow::textChangedSlot(const QString &newText)
+{
+ sendButton->setEnabled(!newText.isEmpty());
+}
+
+void ChatMainWindow::sendClickedSlot()
+{
+ //emit message(m_nickname, messageLineEdit->text());
+ QDBusMessage msg = QDBusMessage::createSignal("/", "com.trolltech.chat", "message");
+ msg << m_nickname << messageLineEdit->text();
+ QDBusConnection::sessionBus().send(msg);
+ messageLineEdit->setText(QString());
+}
+
+void ChatMainWindow::changeNickname()
+{
+ NicknameDialog dialog(this);
+ if (dialog.exec() == QDialog::Accepted) {
+ QString old = m_nickname;
+ m_nickname = dialog.nickname->text().trimmed();
+ emit action(old, QString("is now known as %1").arg(m_nickname));
+ }
+}
+
+void ChatMainWindow::aboutQt()
+{
+ QMessageBox::aboutQt(this);
+}
+
+void ChatMainWindow::exiting()
+{
+ emit action(m_nickname, QLatin1String("leaves the chat"));
+}
+
+NicknameDialog::NicknameDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ setupUi(this);
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ qWarning("Cannot connect to the D-Bus session bus.\n"
+ "Please check your system settings and try again.\n");
+ return 1;
+ }
+
+ ChatMainWindow chat;
+ chat.show();
+ return app.exec();
+}
diff --git a/examples/dbus/dbus-chat/chat.h b/examples/dbus/dbus-chat/chat.h
new file mode 100644
index 0000000000..c7d7b6d2a8
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CHAT_H
+#define CHAT_H
+
+#include <QtCore/QStringList>
+#include <QtDBus/QtDBus>
+#include "ui_chatmainwindow.h"
+#include "ui_chatsetnickname.h"
+
+class ChatMainWindow: public QMainWindow, Ui::ChatMainWindow
+{
+ Q_OBJECT
+ QString m_nickname;
+ QStringList m_messages;
+public:
+ ChatMainWindow();
+ ~ChatMainWindow();
+
+ void rebuildHistory();
+
+signals:
+ void message(const QString &nickname, const QString &text);
+ void action(const QString &nickname, const QString &text);
+
+private slots:
+ void messageSlot(const QString &nickname, const QString &text);
+ void actionSlot(const QString &nickname, const QString &text);
+ void textChangedSlot(const QString &newText);
+ void sendClickedSlot();
+ void changeNickname();
+ void aboutQt();
+ void exiting();
+};
+
+class NicknameDialog: public QDialog, public Ui::NicknameDialog
+{
+ Q_OBJECT
+public:
+ NicknameDialog(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/dbus/dbus-chat/chat_adaptor.cpp b/examples/dbus/dbus-chat/chat_adaptor.cpp
new file mode 100644
index 0000000000..553e6e10cc
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_adaptor.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -i chat_adaptor.h -a :chat_adaptor.cpp com.trolltech.chat.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+**
+****************************************************************************/
+
+#include "chat_adaptor.h"
+#include <QtCore/QMetaObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+
+/*
+ * Implementation of adaptor class ChatAdaptor
+ */
+
+ChatAdaptor::ChatAdaptor(QObject *parent)
+ : QDBusAbstractAdaptor(parent)
+{
+ // constructor
+ setAutoRelaySignals(true);
+}
+
+ChatAdaptor::~ChatAdaptor()
+{
+ // destructor
+}
+
diff --git a/examples/dbus/dbus-chat/chat_adaptor.h b/examples/dbus/dbus-chat/chat_adaptor.h
new file mode 100644
index 0000000000..2558ceb29f
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_adaptor.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -a chat_adaptor.h: com.trolltech.chat.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** This file may have been hand-edited. Look for HAND-EDIT comments
+** before re-generating it.
+**
+****************************************************************************/
+
+#ifndef CHAT_ADAPTOR_H_1257535021
+#define CHAT_ADAPTOR_H_1257535021
+
+#include <QtCore/QObject>
+#include <QtDBus/QtDBus>
+
+QT_BEGIN_NAMESPACE
+class QByteArray;
+template<class T> class QList;
+template<class Key, class Value> class QMap;
+class QString;
+class QStringList;
+class QVariant;
+QT_END_NAMESPACE
+
+/*
+ * Adaptor class for interface com.trolltech.chat
+ */
+class ChatAdaptor: public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.chat")
+ Q_CLASSINFO("D-Bus Introspection", ""
+" <interface name=\"com.trolltech.chat\">\n"
+" <signal name=\"message\">\n"
+" <arg direction=\"out\" type=\"s\" name=\"nickname\"/>\n"
+" <arg direction=\"out\" type=\"s\" name=\"text\"/>\n"
+" </signal>\n"
+" <signal name=\"action\">\n"
+" <arg direction=\"out\" type=\"s\" name=\"nickname\"/>\n"
+" <arg direction=\"out\" type=\"s\" name=\"text\"/>\n"
+" </signal>\n"
+" </interface>\n"
+ "")
+public:
+ ChatAdaptor(QObject *parent);
+ virtual ~ChatAdaptor();
+
+public: // PROPERTIES
+public Q_SLOTS: // METHODS
+Q_SIGNALS: // SIGNALS
+ void action(const QString &nickname, const QString &text);
+ void message(const QString &nickname, const QString &text);
+};
+
+#endif
diff --git a/examples/dbus/dbus-chat/chat_interface.cpp b/examples/dbus/dbus-chat/chat_interface.cpp
new file mode 100644
index 0000000000..ea472506de
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_interface.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -i chat_interface.h -p :chat_interface.cpp com.trolltech.chat.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** This file may have been hand-edited. Look for HAND-EDIT comments
+** before re-generating it.
+**
+****************************************************************************/
+
+#include "chat_interface.h"
+/*
+ * Implementation of interface class ComTrolltechChatInterface
+ */
+
+ComTrolltechChatInterface::ComTrolltechChatInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+ComTrolltechChatInterface::~ComTrolltechChatInterface()
+{
+}
+
diff --git a/examples/dbus/dbus-chat/chat_interface.h b/examples/dbus/dbus-chat/chat_interface.h
new file mode 100644
index 0000000000..8db1b4f420
--- /dev/null
+++ b/examples/dbus/dbus-chat/chat_interface.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -p chat_interface.h: com.trolltech.chat.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+**
+****************************************************************************/
+
+#ifndef CHAT_INTERFACE_H_1257535021
+#define CHAT_INTERFACE_H_1257535021
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface com.trolltech.chat
+ */
+class ComTrolltechChatInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "com.trolltech.chat"; }
+
+public:
+ ComTrolltechChatInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~ComTrolltechChatInterface();
+
+public Q_SLOTS: // METHODS
+Q_SIGNALS: // SIGNALS
+ void action(const QString &nickname, const QString &text);
+ void message(const QString &nickname, const QString &text);
+};
+
+namespace com {
+ namespace trolltech {
+ typedef ::ComTrolltechChatInterface chat;
+ }
+}
+#endif
diff --git a/examples/dbus/dbus-chat/chatmainwindow.ui b/examples/dbus/dbus-chat/chatmainwindow.ui
new file mode 100644
index 0000000000..0616dcb137
--- /dev/null
+++ b/examples/dbus/dbus-chat/chatmainwindow.ui
@@ -0,0 +1,185 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>ChatMainWindow</class>
+ <widget class="QMainWindow" name="ChatMainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>QtDBus Chat</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTextBrowser" name="chatHistory" >
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" >
+ <string>Messages sent and received from other users</string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Message:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>messageLineEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="messageLineEdit" />
+ </item>
+ <item>
+ <widget class="QPushButton" name="sendButton" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" >
+ <string>Sends a message to other people</string>
+ </property>
+ <property name="whatsThis" >
+ <string/>
+ </property>
+ <property name="text" >
+ <string>Send</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuQuit" >
+ <property name="title" >
+ <string>Help</string>
+ </property>
+ <addaction name="actionAboutQt" />
+ </widget>
+ <widget class="QMenu" name="menuFile" >
+ <property name="title" >
+ <string>File</string>
+ </property>
+ <addaction name="actionChangeNickname" />
+ <addaction name="separator" />
+ <addaction name="actionQuit" />
+ </widget>
+ <addaction name="menuFile" />
+ <addaction name="menuQuit" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <action name="actionQuit" >
+ <property name="text" >
+ <string>Quit</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="actionAboutQt" >
+ <property name="text" >
+ <string>About Qt...</string>
+ </property>
+ </action>
+ <action name="actionChangeNickname" >
+ <property name="text" >
+ <string>Change nickname...</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+N</string>
+ </property>
+ </action>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <tabstops>
+ <tabstop>chatHistory</tabstop>
+ <tabstop>messageLineEdit</tabstop>
+ <tabstop>sendButton</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>messageLineEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>sendButton</receiver>
+ <slot>animateClick()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>299</x>
+ <y>554</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>744</x>
+ <y>551</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>actionQuit</sender>
+ <signal>triggered(bool)</signal>
+ <receiver>ChatMainWindow</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>-1</x>
+ <y>-1</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>399</x>
+ <y>299</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/dbus/dbus-chat/chatsetnickname.ui b/examples/dbus/dbus-chat/chatsetnickname.ui
new file mode 100644
index 0000000000..fb9894e09f
--- /dev/null
+++ b/examples/dbus/dbus-chat/chatsetnickname.ui
@@ -0,0 +1,149 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>NicknameDialog</class>
+ <widget class="QDialog" name="NicknameDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>396</width>
+ <height>105</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>1</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle" >
+ <string>Set nickname</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>1</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>New nickname:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="nickname" />
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>131</width>
+ <height>31</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="okButton" >
+ <property name="text" >
+ <string>OK</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="cancelButton" >
+ <property name="text" >
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>okButton</sender>
+ <signal>clicked()</signal>
+ <receiver>NicknameDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>278</x>
+ <y>253</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>96</x>
+ <y>254</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>cancelButton</sender>
+ <signal>clicked()</signal>
+ <receiver>NicknameDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>369</x>
+ <y>253</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>179</x>
+ <y>282</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/dbus/dbus-chat/com.trolltech.chat.xml b/examples/dbus/dbus-chat/com.trolltech.chat.xml
new file mode 100644
index 0000000000..618c8c4dcc
--- /dev/null
+++ b/examples/dbus/dbus-chat/com.trolltech.chat.xml
@@ -0,0 +1,15 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="com.trolltech.chat">
+ <signal name="message">
+ <arg name="nickname" type="s" direction="out"/>
+ <arg name="text" type="s" direction="out"/>
+ </signal>
+ <signal name="action">
+ <arg name="nickname" type="s" direction="out"/>
+ <arg name="text" type="s" direction="out"/>
+ </signal>
+ </interface>
+</node>
+
diff --git a/examples/dbus/dbus-chat/dbus-chat.pro b/examples/dbus/dbus-chat/dbus-chat.pro
new file mode 100644
index 0000000000..b474ff8c15
--- /dev/null
+++ b/examples/dbus/dbus-chat/dbus-chat.pro
@@ -0,0 +1,21 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG += qdbus
+
+# Input
+HEADERS += chat.h chat_adaptor.h chat_interface.h
+SOURCES += chat.cpp chat_adaptor.cpp chat_interface.cpp
+FORMS += chatmainwindow.ui chatsetnickname.ui
+
+#DBUS_ADAPTORS += com.trolltech.chat.xml
+#DBUS_INTERFACES += com.trolltech.chat.xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/chat
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/chat
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/dbus.pro b/examples/dbus/dbus.pro
new file mode 100644
index 0000000000..90865bd3f6
--- /dev/null
+++ b/examples/dbus/dbus.pro
@@ -0,0 +1,17 @@
+TEMPLATE = subdirs
+SUBDIRS = listnames \
+ pingpong \
+ complexpingpong
+
+!contains(QT_CONFIG, no-gui) {
+ SUBDIRS += dbus-chat \
+ remotecontrolledcar
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus
+sources.files = *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/listnames/listnames.cpp b/examples/dbus/listnames/listnames.cpp
new file mode 100644
index 0000000000..40bb032369
--- /dev/null
+++ b/examples/dbus/listnames/listnames.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDebug>
+#include <QtCore/QStringList>
+#include <QtDBus/QtDBus>
+
+void method1()
+{
+ qDebug() << "Method 1:";
+
+ QDBusReply<QStringList> reply = QDBusConnection::sessionBus().interface()->registeredServiceNames();
+ if (!reply.isValid()) {
+ qDebug() << "Error:" << reply.error().message();
+ exit(1);
+ }
+ foreach (QString name, reply.value())
+ qDebug() << name;
+}
+
+void method2()
+{
+ qDebug() << "Method 2:";
+
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ QDBusInterface dbus_iface("org.freedesktop.DBus", "/org/freedesktop/DBus",
+ "org.freedesktop.DBus", bus);
+ qDebug() << dbus_iface.call("ListNames").arguments().at(0);
+}
+
+void method3()
+{
+ qDebug() << "Method 3:";
+ qDebug() << QDBusConnection::sessionBus().interface()->registeredServiceNames().value();
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
+ "To start it, run:\n"
+ "\teval `dbus-launch --auto-syntax`\n");
+ return 1;
+ }
+
+ method1();
+ method2();
+ method3();
+
+ return 0;
+}
diff --git a/examples/dbus/listnames/listnames.pro b/examples/dbus/listnames/listnames.pro
new file mode 100644
index 0000000000..c965de451a
--- /dev/null
+++ b/examples/dbus/listnames/listnames.pro
@@ -0,0 +1,19 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT -= gui
+CONFIG += qdbus
+win32:CONFIG += console
+
+# Input
+SOURCES += listnames.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/listnames
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/listnames
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/dbus/pingpong/ping-common.h b/examples/dbus/pingpong/ping-common.h
new file mode 100644
index 0000000000..532517394b
--- /dev/null
+++ b/examples/dbus/pingpong/ping-common.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#define SERVICE_NAME "com.trolltech.QtDBus.PingExample"
diff --git a/examples/dbus/pingpong/ping.cpp b/examples/dbus/pingpong/ping.cpp
new file mode 100644
index 0000000000..67aaf571bc
--- /dev/null
+++ b/examples/dbus/pingpong/ping.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdio.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtDBus/QtDBus>
+
+#include "ping-common.h"
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
+ "To start it, run:\n"
+ "\teval `dbus-launch --auto-syntax`\n");
+ return 1;
+ }
+
+ QDBusInterface iface(SERVICE_NAME, "/", "", QDBusConnection::sessionBus());
+ if (iface.isValid()) {
+ QDBusReply<QString> reply = iface.call("ping", argc > 1 ? argv[1] : "");
+ if (reply.isValid()) {
+ printf("Reply was: %s\n", qPrintable(reply.value()));
+ return 0;
+ }
+
+ fprintf(stderr, "Call failed: %s\n", qPrintable(reply.error().message()));
+ return 1;
+ }
+
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ return 1;
+}
diff --git a/examples/dbus/pingpong/ping.pro b/examples/dbus/pingpong/ping.pro
new file mode 100644
index 0000000000..7166dba16e
--- /dev/null
+++ b/examples/dbus/pingpong/ping.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET = ping
+DEPENDPATH += .
+INCLUDEPATH += .
+QT -= gui
+CONFIG += qdbus
+
+# Input
+HEADERS += ping-common.h
+SOURCES += ping.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/pingpong
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/pingpong/pingpong.pro b/examples/dbus/pingpong/pingpong.pro
new file mode 100644
index 0000000000..07fca74c9a
--- /dev/null
+++ b/examples/dbus/pingpong/pingpong.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+win32:CONFIG += console
+SUBDIRS = ping.pro pong.pro
diff --git a/examples/dbus/pingpong/pong.cpp b/examples/dbus/pingpong/pong.cpp
new file mode 100644
index 0000000000..a7c0ad392c
--- /dev/null
+++ b/examples/dbus/pingpong/pong.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QTimer>
+#include <QtDBus/QtDBus>
+
+#include "ping-common.h"
+#include "pong.h"
+
+QString Pong::ping(const QString &arg)
+{
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
+ return QString("ping(\"%1\") got called").arg(arg);
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (!QDBusConnection::sessionBus().isConnected()) {
+ fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
+ "To start it, run:\n"
+ "\teval `dbus-launch --auto-syntax`\n");
+ return 1;
+ }
+
+ if (!QDBusConnection::sessionBus().registerService(SERVICE_NAME)) {
+ fprintf(stderr, "%s\n",
+ qPrintable(QDBusConnection::sessionBus().lastError().message()));
+ exit(1);
+ }
+
+ Pong pong;
+ QDBusConnection::sessionBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots);
+
+ app.exec();
+ return 0;
+}
diff --git a/examples/dbus/pingpong/pong.h b/examples/dbus/pingpong/pong.h
new file mode 100644
index 0000000000..1b53f11bbc
--- /dev/null
+++ b/examples/dbus/pingpong/pong.h
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PONG_H
+#define PONG_H
+
+#include <QtCore/QObject>
+
+class Pong: public QObject
+{
+ Q_OBJECT
+public slots:
+ Q_SCRIPTABLE QString ping(const QString &arg);
+};
+
+#endif
diff --git a/examples/dbus/pingpong/pong.pro b/examples/dbus/pingpong/pong.pro
new file mode 100644
index 0000000000..4b18cc5c93
--- /dev/null
+++ b/examples/dbus/pingpong/pong.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET = pong
+DEPENDPATH += .
+INCLUDEPATH += .
+QT -= gui
+CONFIG += qdbus
+
+# Input
+HEADERS += ping-common.h pong.h
+SOURCES += pong.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/pingpong
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/pingpong
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/remotecontrolledcar/car/car.cpp b/examples/dbus/remotecontrolledcar/car/car.cpp
new file mode 100644
index 0000000000..50f8f24d3e
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "car.h"
+#include <QtGui/QtGui>
+#include <math.h>
+
+static const double Pi = 3.14159265358979323846264338327950288419717;
+
+QRectF Car::boundingRect() const
+{
+ return QRectF(-35, -81, 70, 115);
+}
+
+Car::Car() : color(Qt::green), wheelsAngle(0), speed(0)
+{
+ startTimer(1000 / 33);
+ setFlag(QGraphicsItem::ItemIsMovable, true);
+ setFlag(QGraphicsItem::ItemIsFocusable, true);
+}
+
+void Car::accelerate()
+{
+ if (speed < 10)
+ ++speed;
+}
+
+void Car::decelerate()
+{
+ if (speed > -10)
+ --speed;
+}
+
+void Car::turnLeft()
+{
+ if (wheelsAngle > -30)
+ wheelsAngle -= 5;
+}
+
+void Car::turnRight()
+{
+ if (wheelsAngle < 30)
+ wheelsAngle += 5;
+}
+
+void Car::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ painter->setBrush(Qt::gray);
+ painter->drawRect(-20, -58, 40, 2); // front axel
+ painter->drawRect(-20, 7, 40, 2); // rear axel
+
+ painter->setBrush(color);
+ painter->drawRect(-25, -79, 50, 10); // front wing
+
+ painter->drawEllipse(-25, -48, 50, 20); // side pods
+ painter->drawRect(-25, -38, 50, 35); // side pods
+ painter->drawRect(-5, 9, 10, 10); // back pod
+
+ painter->drawEllipse(-10, -81, 20, 100); // main body
+
+ painter->drawRect(-17, 19, 34, 15); // rear wing
+
+ painter->setBrush(Qt::black);
+ painter->drawPie(-5, -51, 10, 15, 0, 180 * 16);
+ painter->drawRect(-5, -44, 10, 10); // cocpit
+
+ painter->save();
+ painter->translate(-20, -58);
+ painter->rotate(wheelsAngle);
+ painter->drawRect(-10, -7, 10, 15); // front left
+ painter->restore();
+
+ painter->save();
+ painter->translate(20, -58);
+ painter->rotate(wheelsAngle);
+ painter->drawRect(0, -7, 10, 15); // front left
+ painter->restore();
+
+ painter->drawRect(-30, 0, 12, 17); // rear left
+ painter->drawRect(19, 0, 12, 17); // rear right
+}
+
+void Car::timerEvent(QTimerEvent *event)
+{
+ Q_UNUSED(event);
+
+ const qreal axelDistance = 54;
+ qreal wheelsAngleRads = (wheelsAngle * Pi) / 180;
+ qreal turnDistance = ::cos(wheelsAngleRads) * axelDistance * 2;
+ qreal turnRateRads = wheelsAngleRads / turnDistance; // rough estimate
+ qreal turnRate = (turnRateRads * 180) / Pi;
+ qreal rotation = speed * turnRate;
+
+ rotate(rotation);
+ translate(0, -speed);
+ update();
+}
diff --git a/examples/dbus/remotecontrolledcar/car/car.h b/examples/dbus/remotecontrolledcar/car/car.h
new file mode 100644
index 0000000000..3db41d7770
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CAR_H
+#define CAR_H
+
+#include <QGraphicsObject>
+#include <QBrush>
+
+class Car : public QGraphicsObject
+{
+ Q_OBJECT
+public:
+ Car();
+ QRectF boundingRect() const;
+
+public Q_SLOTS:
+ void accelerate();
+ void decelerate();
+ void turnLeft();
+ void turnRight();
+
+Q_SIGNALS:
+ void crashed();
+
+protected:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ void timerEvent(QTimerEvent *event);
+
+private:
+ QBrush color;
+ qreal wheelsAngle; // used when applying rotation
+ qreal speed; // delta movement along the body axis
+};
+
+#endif // CAR_H
diff --git a/examples/dbus/remotecontrolledcar/car/car.pro b/examples/dbus/remotecontrolledcar/car/car.pro
new file mode 100644
index 0000000000..0d7971f9d7
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.pro
@@ -0,0 +1,22 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Mon Aug 28 19:50:14 2006
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG += qdbus
+
+# Input
+# DBUS_ADAPTORS += car.xml
+HEADERS += car.h car_adaptor.h
+SOURCES += car.cpp main.cpp car_adaptor.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/car
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/car
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/remotecontrolledcar/car/car.xml b/examples/dbus/remotecontrolledcar/car/car.xml
new file mode 100644
index 0000000000..641c6982d4
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car.xml
@@ -0,0 +1,11 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/com/trollech/examples/car">
+ <interface name="com.trolltech.Examples.CarInterface">
+ <method name="accelerate"/>
+ <method name="decelerate"/>
+ <method name="turnLeft"/>
+ <method name="turnRight"/>
+ <signal name="crashed"/>
+ </interface>
+</node> \ No newline at end of file
diff --git a/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp b/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp
new file mode 100644
index 0000000000..4ced1f5a9c
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car_adaptor.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -i car_adaptor.h -a :car_adaptor.cpp car.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+**
+****************************************************************************/
+
+#include "car_adaptor.h"
+#include <QtCore/QMetaObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+
+/*
+ * Implementation of adaptor class CarInterfaceAdaptor
+ */
+
+CarInterfaceAdaptor::CarInterfaceAdaptor(QObject *parent)
+ : QDBusAbstractAdaptor(parent)
+{
+ // constructor
+ setAutoRelaySignals(true);
+}
+
+CarInterfaceAdaptor::~CarInterfaceAdaptor()
+{
+ // destructor
+}
+
+void CarInterfaceAdaptor::accelerate()
+{
+ // handle method call com.trolltech.Examples.CarInterface.accelerate
+ QMetaObject::invokeMethod(parent(), "accelerate");
+}
+
+void CarInterfaceAdaptor::decelerate()
+{
+ // handle method call com.trolltech.Examples.CarInterface.decelerate
+ QMetaObject::invokeMethod(parent(), "decelerate");
+}
+
+void CarInterfaceAdaptor::turnLeft()
+{
+ // handle method call com.trolltech.Examples.CarInterface.turnLeft
+ QMetaObject::invokeMethod(parent(), "turnLeft");
+}
+
+void CarInterfaceAdaptor::turnRight()
+{
+ // handle method call com.trolltech.Examples.CarInterface.turnRight
+ QMetaObject::invokeMethod(parent(), "turnRight");
+}
+
diff --git a/examples/dbus/remotecontrolledcar/car/car_adaptor.h b/examples/dbus/remotecontrolledcar/car/car_adaptor.h
new file mode 100644
index 0000000000..c31779fed0
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/car_adaptor.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -a car_adaptor.h: car.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** This file may have been hand-edited. Look for HAND-EDIT comments
+** before re-generating it.
+**
+****************************************************************************/
+
+#ifndef CAR_ADAPTOR_H_1264773009
+#define CAR_ADAPTOR_H_1264773009
+
+#include <QtCore/QObject>
+#include <QtDBus/QtDBus>
+
+QT_BEGIN_NAMESPACE
+class QByteArray;
+template<class T> class QList;
+template<class Key, class Value> class QMap;
+class QString;
+class QStringList;
+class QVariant;
+QT_END_NAMESPACE
+
+/*
+ * Adaptor class for interface com.trolltech.Examples.CarInterface
+ */
+class CarInterfaceAdaptor: public QDBusAbstractAdaptor
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.Examples.CarInterface")
+ Q_CLASSINFO("D-Bus Introspection", ""
+" <interface name=\"com.trolltech.Examples.CarInterface\">\n"
+" <method name=\"accelerate\"/>\n"
+" <method name=\"decelerate\"/>\n"
+" <method name=\"turnLeft\"/>\n"
+" <method name=\"turnRight\"/>\n"
+" <signal name=\"crashed\"/>\n"
+" </interface>\n"
+ "")
+public:
+ CarInterfaceAdaptor(QObject *parent);
+ virtual ~CarInterfaceAdaptor();
+
+public: // PROPERTIES
+public Q_SLOTS: // METHODS
+ void accelerate();
+ void decelerate();
+ void turnLeft();
+ void turnRight();
+Q_SIGNALS: // SIGNALS
+ void crashed();
+};
+
+#endif
diff --git a/examples/dbus/remotecontrolledcar/car/main.cpp b/examples/dbus/remotecontrolledcar/car/main.cpp
new file mode 100644
index 0000000000..342a2b0c5d
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/car/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "car.h"
+#include "car_adaptor.h"
+#include <QtGui/QApplication>
+#include <QtGui/QGraphicsView>
+#include <QtGui/QGraphicsScene>
+#include <QtDBus/QDBusConnection>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ scene.setSceneRect(-500, -500, 1000, 1000);
+ scene.setItemIndexMethod(QGraphicsScene::NoIndex);
+
+ Car *car = new Car();
+ scene.addItem(car);
+
+ QGraphicsView view(&scene);
+ view.setRenderHint(QPainter::Antialiasing);
+ view.setBackgroundBrush(Qt::darkGray);
+ view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Qt DBus Controlled Car"));
+ view.resize(400, 300);
+ view.show();
+
+ new CarInterfaceAdaptor(car);
+ QDBusConnection connection = QDBusConnection::sessionBus();
+ connection.registerObject("/Car", car);
+ connection.registerService("com.trolltech.CarExample");
+
+ return app.exec();
+}
diff --git a/examples/dbus/remotecontrolledcar/controller/car.xml b/examples/dbus/remotecontrolledcar/controller/car.xml
new file mode 100644
index 0000000000..641c6982d4
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/car.xml
@@ -0,0 +1,11 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/com/trollech/examples/car">
+ <interface name="com.trolltech.Examples.CarInterface">
+ <method name="accelerate"/>
+ <method name="decelerate"/>
+ <method name="turnLeft"/>
+ <method name="turnRight"/>
+ <signal name="crashed"/>
+ </interface>
+</node> \ No newline at end of file
diff --git a/examples/dbus/remotecontrolledcar/controller/car_interface.cpp b/examples/dbus/remotecontrolledcar/controller/car_interface.cpp
new file mode 100644
index 0000000000..e1e6ae4bec
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/car_interface.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -i car_interface.h -p :car_interface.cpp car.xml
+**
+** qqdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** This file may have been hand-edited. Look for HAND-EDIT comments
+** before re-generating it.
+**
+****************************************************************************/
+
+#include "car_interface.h"
+/*
+ * Implementation of interface class ComTrolltechExamplesCarInterfaceInterface
+ */
+
+ComTrolltechExamplesCarInterfaceInterface::ComTrolltechExamplesCarInterfaceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+ComTrolltechExamplesCarInterfaceInterface::~ComTrolltechExamplesCarInterfaceInterface()
+{
+}
+
diff --git a/examples/dbus/remotecontrolledcar/controller/car_interface.h b/examples/dbus/remotecontrolledcar/controller/car_interface.h
new file mode 100644
index 0000000000..e7e3774c17
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/car_interface.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+**
+** This file was generated by qdbusxml2cpp version 0.7
+** Command line was: qdbusxml2cpp -p car_interface.h: car.xml
+**
+** qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+**
+****************************************************************************/
+
+#ifndef CAR_INTERFACE_H_1264772826
+#define CAR_INTERFACE_H_1264772826
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface com.trolltech.Examples.CarInterface
+ */
+class ComTrolltechExamplesCarInterfaceInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "com.trolltech.Examples.CarInterface"; }
+
+public:
+ ComTrolltechExamplesCarInterfaceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~ComTrolltechExamplesCarInterfaceInterface();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<> accelerate()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("accelerate"), argumentList);
+ }
+
+ inline QDBusPendingReply<> decelerate()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("decelerate"), argumentList);
+ }
+
+ inline QDBusPendingReply<> turnLeft()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("turnLeft"), argumentList);
+ }
+
+ inline QDBusPendingReply<> turnRight()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("turnRight"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void crashed();
+};
+
+namespace com {
+ namespace trolltech {
+ namespace Examples {
+ typedef ::ComTrolltechExamplesCarInterfaceInterface CarInterface;
+ }
+ }
+}
+#endif
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.cpp b/examples/dbus/remotecontrolledcar/controller/controller.cpp
new file mode 100644
index 0000000000..8691aafa92
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "controller.h"
+#include "car_interface.h"
+
+Controller::Controller(QWidget *parent)
+ : QWidget(parent)
+{
+ ui.setupUi(this);
+ car = new com::trolltech::Examples::CarInterface("com.trolltech.CarExample", "/Car",
+ QDBusConnection::sessionBus(), this);
+ startTimer(1000);
+}
+
+void Controller::timerEvent(QTimerEvent *event)
+{
+ Q_UNUSED(event);
+ if (car->isValid())
+ ui.label->setText("connected");
+ else
+ ui.label->setText("disconnected");
+}
+
+void Controller::on_accelerate_clicked()
+{
+ car->accelerate();
+}
+
+void Controller::on_decelerate_clicked()
+{
+ car->decelerate();
+}
+
+void Controller::on_left_clicked()
+{
+ car->turnLeft();
+}
+
+void Controller::on_right_clicked()
+{
+ car->turnRight();
+}
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.h b/examples/dbus/remotecontrolledcar/controller/controller.h
new file mode 100644
index 0000000000..3fe172e2b7
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONTROLLER_H
+#define CONTROLLER_H
+
+#include "ui_controller.h"
+#include "car_interface.h"
+
+class Controller : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Controller(QWidget *parent = 0);
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private slots:
+ void on_accelerate_clicked();
+ void on_decelerate_clicked();
+ void on_left_clicked();
+ void on_right_clicked();
+
+private:
+ Ui::Controller ui;
+ com::trolltech::Examples::CarInterface *car;
+};
+
+#endif
+
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.pro b/examples/dbus/remotecontrolledcar/controller/controller.pro
new file mode 100644
index 0000000000..71cdb54b17
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.pro
@@ -0,0 +1,23 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue Aug 29 12:28:05 2006
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG += qdbus
+
+# Input
+# DBUS_INTERFACES += car.xml
+FORMS += controller.ui
+HEADERS += car_interface.h controller.h
+SOURCES += main.cpp car_interface.cpp controller.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/controller
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xml
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar/controller
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dbus/remotecontrolledcar/controller/controller.ui b/examples/dbus/remotecontrolledcar/controller/controller.ui
new file mode 100644
index 0000000000..379015bf30
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/controller.ui
@@ -0,0 +1,64 @@
+<ui version="4.0" >
+ <class>Controller</class>
+ <widget class="QWidget" name="Controller" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>255</width>
+ <height>111</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Controller</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="1" column="1" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Controller</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QPushButton" name="decelerate" >
+ <property name="text" >
+ <string>Decelerate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QPushButton" name="accelerate" >
+ <property name="text" >
+ <string>Accelerate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QPushButton" name="right" >
+ <property name="text" >
+ <string>Right</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QPushButton" name="left" >
+ <property name="text" >
+ <string>Left</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/dbus/remotecontrolledcar/controller/main.cpp b/examples/dbus/remotecontrolledcar/controller/main.cpp
new file mode 100644
index 0000000000..5b536117c8
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/controller/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtDBus>
+
+#include "controller.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Controller controller;
+ controller.show();
+ return app.exec();
+}
diff --git a/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro
new file mode 100644
index 0000000000..586507683c
--- /dev/null
+++ b/examples/dbus/remotecontrolledcar/remotecontrolledcar.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = car \
+ controller
+
+# install
+sources.files = *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dbus/remotecontrolledcar
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/desktop/README b/examples/desktop/README
new file mode 100644
index 0000000000..efe569a604
--- /dev/null
+++ b/examples/desktop/README
@@ -0,0 +1,41 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/desktop/desktop.pro b/examples/desktop/desktop.pro
new file mode 100644
index 0000000000..eb3cbaca42
--- /dev/null
+++ b/examples/desktop/desktop.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = screenshot
+
+!symbian:contains(QT_CONFIG, svg): SUBDIRS += 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/desktop/screenshot/main.cpp b/examples/desktop/screenshot/main.cpp
new file mode 100644
index 0000000000..c2930f7513
--- /dev/null
+++ b/examples/desktop/screenshot/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/desktop/screenshot/screenshot.cpp b/examples/desktop/screenshot/screenshot.cpp
new file mode 100644
index 0000000000..0d7a18842a
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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.toAscii());
+}
+//! [3]
+
+//! [4]
+void Screenshot::shootScreen()
+{
+ if (delaySpinBox->value() != 0)
+ qApp->beep();
+//! [4]
+ originalPixmap = QPixmap(); // clear image for low memory situations
+ // on embedded devices.
+//! [5]
+ originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
+ 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/desktop/screenshot/screenshot.h b/examples/desktop/screenshot/screenshot.h
new file mode 100644
index 0000000000..03e0508575
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/desktop/screenshot/screenshot.pro b/examples/desktop/screenshot/screenshot.pro
new file mode 100644
index 0000000000..ab2700fed1
--- /dev/null
+++ b/examples/desktop/screenshot/screenshot.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/README b/examples/dialogs/README
new file mode 100644
index 0000000000..ab0f884fcb
--- /dev/null
+++ b/examples/dialogs/README
@@ -0,0 +1,40 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/dialogs/classwizard/classwizard.cpp b/examples/dialogs/classwizard/classwizard.cpp
new file mode 100644
index 0000000000..5247d7e2ae
--- /dev/null
+++ b/examples/dialogs/classwizard/classwizard.cpp
@@ -0,0 +1,430 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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.toAscii() + "\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.toAscii() + "\n";
+ block += "*/\n";
+ block += "\n";
+ }
+ block += "#include \"" + header.toAscii() + "\"\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::convertSeparators(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/dialogs/classwizard/classwizard.h b/examples/dialogs/classwizard/classwizard.h
new file mode 100644
index 0000000000..c2833ae07f
--- /dev/null
+++ b/examples/dialogs/classwizard/classwizard.h
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/classwizard/classwizard.pro b/examples/dialogs/classwizard/classwizard.pro
new file mode 100644
index 0000000000..13341c4f0e
--- /dev/null
+++ b/examples/dialogs/classwizard/classwizard.pro
@@ -0,0 +1,12 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/classwizard/classwizard.qrc b/examples/dialogs/classwizard/classwizard.qrc
new file mode 100644
index 0000000000..41a5ddc7d1
--- /dev/null
+++ b/examples/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/dialogs/classwizard/images/background.png b/examples/dialogs/classwizard/images/background.png
new file mode 100644
index 0000000000..44c7badb85
--- /dev/null
+++ b/examples/dialogs/classwizard/images/background.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/banner.png b/examples/dialogs/classwizard/images/banner.png
new file mode 100644
index 0000000000..3169152b8e
--- /dev/null
+++ b/examples/dialogs/classwizard/images/banner.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/logo1.png b/examples/dialogs/classwizard/images/logo1.png
new file mode 100644
index 0000000000..f9b594aafc
--- /dev/null
+++ b/examples/dialogs/classwizard/images/logo1.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/logo2.png b/examples/dialogs/classwizard/images/logo2.png
new file mode 100644
index 0000000000..5dcbd4669d
--- /dev/null
+++ b/examples/dialogs/classwizard/images/logo2.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/logo3.png b/examples/dialogs/classwizard/images/logo3.png
new file mode 100644
index 0000000000..9fd3ea2358
--- /dev/null
+++ b/examples/dialogs/classwizard/images/logo3.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/watermark1.png b/examples/dialogs/classwizard/images/watermark1.png
new file mode 100644
index 0000000000..0091f5c17a
--- /dev/null
+++ b/examples/dialogs/classwizard/images/watermark1.png
Binary files differ
diff --git a/examples/dialogs/classwizard/images/watermark2.png b/examples/dialogs/classwizard/images/watermark2.png
new file mode 100644
index 0000000000..3b88f2e360
--- /dev/null
+++ b/examples/dialogs/classwizard/images/watermark2.png
Binary files differ
diff --git a/examples/dialogs/classwizard/main.cpp b/examples/dialogs/classwizard/main.cpp
new file mode 100644
index 0000000000..8609c0fa08
--- /dev/null
+++ b/examples/dialogs/classwizard/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/configdialog/configdialog.cpp b/examples/dialogs/configdialog/configdialog.cpp
new file mode 100644
index 0000000000..0e1de0c61c
--- /dev/null
+++ b/examples/dialogs/configdialog/configdialog.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/dialogs/configdialog/configdialog.h b/examples/dialogs/configdialog/configdialog.h
new file mode 100644
index 0000000000..3835daff86
--- /dev/null
+++ b/examples/dialogs/configdialog/configdialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/configdialog/configdialog.pro b/examples/dialogs/configdialog/configdialog.pro
new file mode 100644
index 0000000000..e73e7401e5
--- /dev/null
+++ b/examples/dialogs/configdialog/configdialog.pro
@@ -0,0 +1,16 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
diff --git a/examples/dialogs/configdialog/configdialog.qrc b/examples/dialogs/configdialog/configdialog.qrc
new file mode 100644
index 0000000000..31d0d49666
--- /dev/null
+++ b/examples/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/dialogs/configdialog/images/config.png b/examples/dialogs/configdialog/images/config.png
new file mode 100644
index 0000000000..5c14d5f470
--- /dev/null
+++ b/examples/dialogs/configdialog/images/config.png
Binary files differ
diff --git a/examples/dialogs/configdialog/images/query.png b/examples/dialogs/configdialog/images/query.png
new file mode 100644
index 0000000000..ea9e291eeb
--- /dev/null
+++ b/examples/dialogs/configdialog/images/query.png
Binary files differ
diff --git a/examples/dialogs/configdialog/images/update.png b/examples/dialogs/configdialog/images/update.png
new file mode 100644
index 0000000000..3cb8ba6c77
--- /dev/null
+++ b/examples/dialogs/configdialog/images/update.png
Binary files differ
diff --git a/examples/dialogs/configdialog/main.cpp b/examples/dialogs/configdialog/main.cpp
new file mode 100644
index 0000000000..3b7b8c1c45
--- /dev/null
+++ b/examples/dialogs/configdialog/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/configdialog/pages.cpp b/examples/dialogs/configdialog/pages.cpp
new file mode 100644
index 0000000000..f69ec53f83
--- /dev/null
+++ b/examples/dialogs/configdialog/pages.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/dialogs/configdialog/pages.h b/examples/dialogs/configdialog/pages.h
new file mode 100644
index 0000000000..ef35b3d0f3
--- /dev/null
+++ b/examples/dialogs/configdialog/pages.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/dialogs.pro b/examples/dialogs/dialogs.pro
new file mode 100644
index 0000000000..50d665f45e
--- /dev/null
+++ b/examples/dialogs/dialogs.pro
@@ -0,0 +1,19 @@
+TEMPLATE = subdirs
+SUBDIRS = classwizard \
+ configdialog \
+ standarddialogs \
+ tabdialog \
+ trivialwizard
+
+!symbian:!wince*: SUBDIRS += licensewizard \
+ extension \
+ findfiles
+
+wince*: SUBDIRS += sipdialog
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/dialogs
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/extension/extension.pro b/examples/dialogs/extension/extension.pro
new file mode 100644
index 0000000000..4f56a949ff
--- /dev/null
+++ b/examples/dialogs/extension/extension.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/extension/finddialog.cpp b/examples/dialogs/extension/finddialog.cpp
new file mode 100644
index 0000000000..313e8e4201
--- /dev/null
+++ b/examples/dialogs/extension/finddialog.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+
+ buttonBox = new QDialogButtonBox(Qt::Vertical);
+ buttonBox->addButton(findButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(moreButton, QDialogButtonBox::ActionRole);
+//! [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]
+ 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);
+ leftLayout->addStretch(1);
+
+ 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);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Extension"));
+//! [4] //! [5]
+ extension->hide();
+}
+//! [5]
diff --git a/examples/dialogs/extension/finddialog.h b/examples/dialogs/extension/finddialog.h
new file mode 100644
index 0000000000..0727bc2894
--- /dev/null
+++ b/examples/dialogs/extension/finddialog.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/extension/main.cpp b/examples/dialogs/extension/main.cpp
new file mode 100644
index 0000000000..d487faab69
--- /dev/null
+++ b/examples/dialogs/extension/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "finddialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ FindDialog dialog;
+ return dialog.exec();
+}
diff --git a/examples/dialogs/findfiles/findfiles.pro b/examples/dialogs/findfiles/findfiles.pro
new file mode 100644
index 0000000000..8e80b27f33
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/findfiles/main.cpp b/examples/dialogs/findfiles/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/dialogs/findfiles/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/findfiles/window.cpp b/examples/dialogs/findfiles/window.cpp
new file mode 100644
index 0000000000..3d6c0fd398
--- /dev/null
+++ b/examples/dialogs/findfiles/window.cpp
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window(QWidget *parent)
+ : QDialog(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]
+ QHBoxLayout *buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch();
+ buttonsLayout->addWidget(findButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ 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, 3);
+ mainLayout->addLayout(buttonsLayout, 5, 0, 1, 3);
+ 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)"));
+}
+//! [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("File Name") << tr("Size");
+ filesTable->setHorizontalHeaderLabels(labels);
+ filesTable->horizontalHeader()->setResizeMode(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/dialogs/findfiles/window.h b/examples/dialogs/findfiles/window.h
new file mode 100644
index 0000000000..73b065233b
--- /dev/null
+++ b/examples/dialogs/findfiles/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QDialog>
+#include <QDir>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLabel;
+class QPushButton;
+class QTableWidget;
+class QTableWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QDialog
+{
+ 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/dialogs/licensewizard/images/logo.png b/examples/dialogs/licensewizard/images/logo.png
new file mode 100644
index 0000000000..56f17a3e5a
--- /dev/null
+++ b/examples/dialogs/licensewizard/images/logo.png
Binary files differ
diff --git a/examples/dialogs/licensewizard/images/watermark.png b/examples/dialogs/licensewizard/images/watermark.png
new file mode 100644
index 0000000000..124a05068b
--- /dev/null
+++ b/examples/dialogs/licensewizard/images/watermark.png
Binary files differ
diff --git a/examples/dialogs/licensewizard/licensewizard.cpp b/examples/dialogs/licensewizard/licensewizard.cpp
new file mode 100644
index 0000000000..19a0c069e4
--- /dev/null
+++ b/examples/dialogs/licensewizard/licensewizard.cpp
@@ -0,0 +1,359 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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_WS_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()
+{
+ 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."));
+}
diff --git a/examples/dialogs/licensewizard/licensewizard.h b/examples/dialogs/licensewizard/licensewizard.h
new file mode 100644
index 0000000000..432c046444
--- /dev/null
+++ b/examples/dialogs/licensewizard/licensewizard.h
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/licensewizard/licensewizard.pro b/examples/dialogs/licensewizard/licensewizard.pro
new file mode 100644
index 0000000000..2f72bd97f3
--- /dev/null
+++ b/examples/dialogs/licensewizard/licensewizard.pro
@@ -0,0 +1,12 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/dialogs/licensewizard/licensewizard.qrc b/examples/dialogs/licensewizard/licensewizard.qrc
new file mode 100644
index 0000000000..b069938515
--- /dev/null
+++ b/examples/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/dialogs/licensewizard/main.cpp b/examples/dialogs/licensewizard/main.cpp
new file mode 100644
index 0000000000..59e59ac720
--- /dev/null
+++ b/examples/dialogs/licensewizard/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/sipdialog/dialog.cpp b/examples/dialogs/sipdialog/dialog.cpp
new file mode 100644
index 0000000000..c6d5a1767f
--- /dev/null
+++ b/examples/dialogs/sipdialog/dialog.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/dialogs/sipdialog/dialog.h b/examples/dialogs/sipdialog/dialog.h
new file mode 100644
index 0000000000..a97c20880b
--- /dev/null
+++ b/examples/dialogs/sipdialog/dialog.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/sipdialog/main.cpp b/examples/dialogs/sipdialog/main.cpp
new file mode 100644
index 0000000000..bd37e33960
--- /dev/null
+++ b/examples/dialogs/sipdialog/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/dialogs/sipdialog/sipdialog.pro b/examples/dialogs/sipdialog/sipdialog.pro
new file mode 100644
index 0000000000..31794b7866
--- /dev/null
+++ b/examples/dialogs/sipdialog/sipdialog.pro
@@ -0,0 +1,14 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
+
diff --git a/examples/dialogs/standarddialogs/dialog.cpp b/examples/dialogs/standarddialogs/dialog.cpp
new file mode 100644
index 0000000000..0b7728ece4
--- /dev/null
+++ b/examples/dialogs/standarddialogs/dialog.cpp
@@ -0,0 +1,389 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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).")
+
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent)
+{
+ 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()));
+
+ native = new QCheckBox(this);
+ native->setText("Use native file dialog.");
+ native->setChecked(true);
+ QGridLayout *layout = new QGridLayout;
+ 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->addWidget(colorButton, 4, 0);
+ layout->addWidget(colorLabel, 4, 1);
+ layout->addWidget(fontButton, 5, 0);
+ layout->addWidget(fontLabel, 5, 1);
+ layout->addWidget(directoryButton, 6, 0);
+ layout->addWidget(directoryLabel, 6, 1);
+ layout->addWidget(openFileNameButton, 7, 0);
+ layout->addWidget(openFileNameLabel, 7, 1);
+ layout->addWidget(openFileNamesButton, 8, 0);
+ layout->addWidget(openFileNamesLabel, 8, 1);
+ layout->addWidget(saveFileNameButton, 9, 0);
+ layout->addWidget(saveFileNameLabel, 9, 1);
+ layout->addWidget(criticalButton, 10, 0);
+ layout->addWidget(criticalLabel, 10, 1);
+ layout->addWidget(informationButton, 11, 0);
+ layout->addWidget(informationLabel, 11, 1);
+ layout->addWidget(questionButton, 12, 0);
+ layout->addWidget(questionLabel, 12, 1);
+ layout->addWidget(warningButton, 13, 0);
+ layout->addWidget(warningLabel, 13, 1);
+ layout->addWidget(errorButton, 14, 0);
+ layout->addWidget(errorLabel, 14, 1);
+ layout->addWidget(native, 15, 0);
+ setLayout(layout);
+
+ 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()
+{
+ QColor color;
+ if (native->isChecked())
+ color = QColorDialog::getColor(Qt::green, this);
+ else
+ color = QColorDialog::getColor(Qt::green, this, "Select Color", QColorDialog::DontUseNativeDialog);
+
+ if (color.isValid()) {
+ colorLabel->setText(color.name());
+ colorLabel->setPalette(QPalette(color));
+ colorLabel->setAutoFillBackground(true);
+ }
+}
+
+void Dialog::setFont()
+{
+ bool ok;
+ QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this);
+ if (ok) {
+ fontLabel->setText(font.key());
+ fontLabel->setFont(font);
+ }
+}
+
+void Dialog::setExistingDirectory()
+{
+ QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
+ if (!native->isChecked())
+ options |= QFileDialog::DontUseNativeDialog;
+ QString directory = QFileDialog::getExistingDirectory(this,
+ tr("QFileDialog::getExistingDirectory()"),
+ directoryLabel->text(),
+ options);
+ if (!directory.isEmpty())
+ directoryLabel->setText(directory);
+}
+
+void Dialog::setOpenFileName()
+{
+ QFileDialog::Options options;
+ if (!native->isChecked())
+ options |= QFileDialog::DontUseNativeDialog;
+ 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()
+{
+ QFileDialog::Options options;
+ if (!native->isChecked())
+ options |= QFileDialog::DontUseNativeDialog;
+ 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()
+{
+ QFileDialog::Options options;
+ if (!native->isChecked())
+ options |= QFileDialog::DontUseNativeDialog;
+ 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/dialogs/standarddialogs/dialog.h b/examples/dialogs/standarddialogs/dialog.h
new file mode 100644
index 0000000000..9af17d130b
--- /dev/null
+++ b/examples/dialogs/standarddialogs/dialog.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QLabel;
+class QErrorMessage;
+QT_END_NAMESPACE
+
+class Dialog : public QDialog
+{
+ 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:
+ QCheckBox *native;
+ 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;
+
+ QString openFilesPath;
+};
+
+#endif
diff --git a/examples/dialogs/standarddialogs/main.cpp b/examples/dialogs/standarddialogs/main.cpp
new file mode 100644
index 0000000000..2aec376dab
--- /dev/null
+++ b/examples/dialogs/standarddialogs/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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;
+ return dialog.exec();
+}
diff --git a/examples/dialogs/standarddialogs/standarddialogs.pro b/examples/dialogs/standarddialogs/standarddialogs.pro
new file mode 100644
index 0000000000..4fcbeebb1f
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
+
diff --git a/examples/dialogs/tabdialog/main.cpp b/examples/dialogs/tabdialog/main.cpp
new file mode 100644
index 0000000000..87265c3986
--- /dev/null
+++ b/examples/dialogs/tabdialog/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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);
+ return tabdialog.exec();
+}
diff --git a/examples/dialogs/tabdialog/tabdialog.cpp b/examples/dialogs/tabdialog/tabdialog.cpp
new file mode 100644
index 0000000000..62c921c84b
--- /dev/null
+++ b/examples/dialogs/tabdialog/tabdialog.cpp
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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->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/dialogs/tabdialog/tabdialog.h b/examples/dialogs/tabdialog/tabdialog.h
new file mode 100644
index 0000000000..6ae1e15df5
--- /dev/null
+++ b/examples/dialogs/tabdialog/tabdialog.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/dialogs/tabdialog/tabdialog.pro b/examples/dialogs/tabdialog/tabdialog.pro
new file mode 100644
index 0000000000..f327580714
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+wince50standard-x86-msvc2005: LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib ws2.lib
diff --git a/examples/dialogs/trivialwizard/trivialwizard.cpp b/examples/dialogs/trivialwizard/trivialwizard.cpp
new file mode 100644
index 0000000000..2a5c0ae5db
--- /dev/null
+++ b/examples/dialogs/trivialwizard/trivialwizard.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/dialogs/trivialwizard/trivialwizard.pro b/examples/dialogs/trivialwizard/trivialwizard.pro
new file mode 100644
index 0000000000..ffbb8e9aa8
--- /dev/null
+++ b/examples/dialogs/trivialwizard/trivialwizard.pro
@@ -0,0 +1,9 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/draganddrop/README b/examples/draganddrop/README
new file mode 100644
index 0000000000..f4efd2e40b
--- /dev/null
+++ b/examples/draganddrop/README
@@ -0,0 +1,40 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/draganddrop/draganddrop.pro b/examples/draganddrop/draganddrop.pro
new file mode 100644
index 0000000000..9cc0e2bd2f
--- /dev/null
+++ b/examples/draganddrop/draganddrop.pro
@@ -0,0 +1,15 @@
+TEMPLATE = subdirs
+SUBDIRS = draggableicons \
+ draggabletext \
+ dropsite \
+ fridgemagnets \
+ puzzle
+
+contains(QT_CONFIG, svg): SUBDIRS += delayedencoding
+
+wince*: SUBDIRS -= dropsite
+symbian: SUBDIRS -= dropsite
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/draganddrop
+INSTALLS += sources
diff --git a/examples/draganddrop/draggableicons/draggableicons.pro b/examples/draganddrop/draggableicons/draggableicons.pro
new file mode 100644
index 0000000000..f28769adad
--- /dev/null
+++ b/examples/draganddrop/draggableicons/draggableicons.pro
@@ -0,0 +1,15 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000C615
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/draganddrop/draggableicons/draggableicons.qrc b/examples/draganddrop/draggableicons/draggableicons.qrc
new file mode 100644
index 0000000000..63f84ac066
--- /dev/null
+++ b/examples/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/draganddrop/draggableicons/dragwidget.cpp b/examples/draganddrop/draggableicons/dragwidget.cpp
new file mode 100644
index 0000000000..c8c3b134fc
--- /dev/null
+++ b/examples/draganddrop/draggableicons/dragwidget.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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(20, 20);
+ boatIcon->show();
+ boatIcon->setAttribute(Qt::WA_DeleteOnClose);
+
+ QLabel *carIcon = new QLabel(this);
+ carIcon->setPixmap(QPixmap(":/images/car.png"));
+ carIcon->move(120, 20);
+ carIcon->show();
+ carIcon->setAttribute(Qt::WA_DeleteOnClose);
+
+ QLabel *houseIcon = new QLabel(this);
+ houseIcon->setPixmap(QPixmap(":/images/house.png"));
+ houseIcon->move(20, 120);
+ 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/draganddrop/draggableicons/dragwidget.h b/examples/draganddrop/draggableicons/dragwidget.h
new file mode 100644
index 0000000000..f41dbcdf93
--- /dev/null
+++ b/examples/draganddrop/draggableicons/dragwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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/draganddrop/draggableicons/images/boat.png b/examples/draganddrop/draggableicons/images/boat.png
new file mode 100644
index 0000000000..46c894f06b
--- /dev/null
+++ b/examples/draganddrop/draggableicons/images/boat.png
Binary files differ
diff --git a/examples/draganddrop/draggableicons/images/car.png b/examples/draganddrop/draggableicons/images/car.png
new file mode 100644
index 0000000000..3cb35e56cb
--- /dev/null
+++ b/examples/draganddrop/draggableicons/images/car.png
Binary files differ
diff --git a/examples/draganddrop/draggableicons/images/house.png b/examples/draganddrop/draggableicons/images/house.png
new file mode 100644
index 0000000000..ee9d5b1159
--- /dev/null
+++ b/examples/draganddrop/draggableicons/images/house.png
Binary files differ
diff --git a/examples/draganddrop/draggableicons/main.cpp b/examples/draganddrop/draggableicons/main.cpp
new file mode 100644
index 0000000000..7a80b92a8a
--- /dev/null
+++ b/examples/draganddrop/draggableicons/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/draggabletext/draggabletext.pro b/examples/draganddrop/draggabletext/draggabletext.pro
new file mode 100644
index 0000000000..d2e8b0bef8
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draggabletext.pro
@@ -0,0 +1,17 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000CF64
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/draganddrop/draggabletext/draggabletext.qrc b/examples/draganddrop/draggabletext/draggabletext.qrc
new file mode 100644
index 0000000000..b72217d701
--- /dev/null
+++ b/examples/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/draganddrop/draggabletext/draglabel.cpp b/examples/draganddrop/draggabletext/draglabel.cpp
new file mode 100644
index 0000000000..dff09da14f
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draglabel.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/draganddrop/draggabletext/draglabel.h b/examples/draganddrop/draggabletext/draglabel.h
new file mode 100644
index 0000000000..55bf7c3d7c
--- /dev/null
+++ b/examples/draganddrop/draggabletext/draglabel.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/draggabletext/dragwidget.cpp b/examples/draganddrop/draggabletext/dragwidget.cpp
new file mode 100644
index 0000000000..df61c39476
--- /dev/null
+++ b/examples/draganddrop/draggabletext/dragwidget.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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 >= 195) {
+ 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/draganddrop/draggabletext/dragwidget.h b/examples/draganddrop/draggabletext/dragwidget.h
new file mode 100644
index 0000000000..89391a1313
--- /dev/null
+++ b/examples/draganddrop/draggabletext/dragwidget.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/draggabletext/main.cpp b/examples/draganddrop/draggabletext/main.cpp
new file mode 100644
index 0000000000..4d0a121337
--- /dev/null
+++ b/examples/draganddrop/draggabletext/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/draggabletext/words.txt b/examples/draganddrop/draggabletext/words.txt
new file mode 100644
index 0000000000..19b8b0325b
--- /dev/null
+++ b/examples/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/draganddrop/dropsite/droparea.cpp b/examples/draganddrop/dropsite/droparea.cpp
new file mode 100644
index 0000000000..2a83de888e
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/draganddrop/dropsite/droparea.h b/examples/draganddrop/dropsite/droparea.h
new file mode 100644
index 0000000000..9c2259d4d0
--- /dev/null
+++ b/examples/draganddrop/dropsite/droparea.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/dropsite/dropsite.pro b/examples/draganddrop/dropsite/dropsite.pro
new file mode 100644
index 0000000000..22b587ad7a
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsite.pro
@@ -0,0 +1,13 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/draganddrop/dropsite/dropsitewindow.cpp b/examples/draganddrop/dropsite/dropsitewindow.cpp
new file mode 100644
index 0000000000..db7d6e3566
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/draganddrop/dropsite/dropsitewindow.h b/examples/draganddrop/dropsite/dropsitewindow.h
new file mode 100644
index 0000000000..f4cb2a8f61
--- /dev/null
+++ b/examples/draganddrop/dropsite/dropsitewindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/dropsite/main.cpp b/examples/draganddrop/dropsite/main.cpp
new file mode 100644
index 0000000000..8f57cb88a6
--- /dev/null
+++ b/examples/draganddrop/dropsite/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/fridgemagnets/draglabel.cpp b/examples/draganddrop/fridgemagnets/draglabel.cpp
new file mode 100644
index 0000000000..986f0b28c8
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/draglabel.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/draganddrop/fridgemagnets/draglabel.h b/examples/draganddrop/fridgemagnets/draglabel.h
new file mode 100644
index 0000000000..37ebb3a7cd
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/draglabel.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/fridgemagnets/dragwidget.cpp b/examples/draganddrop/fridgemagnets/dragwidget.cpp
new file mode 100644
index 0000000000..aeab3ade12
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/dragwidget.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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]
+ #ifndef Q_WS_S60
+ //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);
+ #endif
+
+ 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/draganddrop/fridgemagnets/dragwidget.h b/examples/draganddrop/fridgemagnets/dragwidget.h
new file mode 100644
index 0000000000..787121e9e7
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/dragwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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/draganddrop/fridgemagnets/fridgemagnets.pro b/examples/draganddrop/fridgemagnets/fridgemagnets.pro
new file mode 100644
index 0000000000..9f9b3a0535
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/fridgemagnets.pro
@@ -0,0 +1,19 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000C610
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
+
+
diff --git a/examples/draganddrop/fridgemagnets/fridgemagnets.qrc b/examples/draganddrop/fridgemagnets/fridgemagnets.qrc
new file mode 100644
index 0000000000..b72217d701
--- /dev/null
+++ b/examples/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/draganddrop/fridgemagnets/main.cpp b/examples/draganddrop/fridgemagnets/main.cpp
new file mode 100644
index 0000000000..1166abbcaa
--- /dev/null
+++ b/examples/draganddrop/fridgemagnets/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/fridgemagnets/words.txt b/examples/draganddrop/fridgemagnets/words.txt
new file mode 100644
index 0000000000..a7e1632b09
--- /dev/null
+++ b/examples/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/draganddrop/puzzle/example.jpg b/examples/draganddrop/puzzle/example.jpg
new file mode 100644
index 0000000000..e09fb70757
--- /dev/null
+++ b/examples/draganddrop/puzzle/example.jpg
Binary files differ
diff --git a/examples/draganddrop/puzzle/main.cpp b/examples/draganddrop/puzzle/main.cpp
new file mode 100644
index 0000000000..60341948ab
--- /dev/null
+++ b/examples/draganddrop/puzzle/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/puzzle/mainwindow.cpp b/examples/draganddrop/puzzle/mainwindow.cpp
new file mode 100644
index 0000000000..ea7cff12ce
--- /dev/null
+++ b/examples/draganddrop/puzzle/mainwindow.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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(400,
+ 400, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+
+ piecesList->clear();
+
+ for (int y = 0; y < 5; ++y) {
+ for (int x = 0; x < 5; ++x) {
+ QPixmap pieceImage = puzzleImage.copy(x*80, y*80, 80, 80);
+ 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);
+
+ piecesList = new PiecesList;
+ puzzleWidget = new PuzzleWidget;
+
+ connect(puzzleWidget, SIGNAL(puzzleCompleted()),
+ this, SLOT(setCompleted()), Qt::QueuedConnection);
+
+ frameLayout->addWidget(piecesList);
+ frameLayout->addWidget(puzzleWidget);
+ setCentralWidget(frame);
+}
diff --git a/examples/draganddrop/puzzle/mainwindow.h b/examples/draganddrop/puzzle/mainwindow.h
new file mode 100644
index 0000000000..283ce97660
--- /dev/null
+++ b/examples/draganddrop/puzzle/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/draganddrop/puzzle/pieceslist.cpp b/examples/draganddrop/puzzle/pieceslist.cpp
new file mode 100644
index 0000000000..db27e7ad13
--- /dev/null
+++ b/examples/draganddrop/puzzle/pieceslist.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "pieceslist.h"
+
+PiecesList::PiecesList(QWidget *parent)
+ : QListWidget(parent)
+{
+ setDragEnabled(true);
+ setViewMode(QListView::IconMode);
+ setIconSize(QSize(60, 60));
+ 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/draganddrop/puzzle/pieceslist.h b/examples/draganddrop/puzzle/pieceslist.h
new file mode 100644
index 0000000000..2068dceb17
--- /dev/null
+++ b/examples/draganddrop/puzzle/pieceslist.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PIECESLIST_H
+#define PIECESLIST_H
+
+#include <QListWidget>
+
+class PiecesList : public QListWidget
+{
+ Q_OBJECT
+
+public:
+ PiecesList(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);
+};
+
+#endif
diff --git a/examples/draganddrop/puzzle/puzzle.pro b/examples/draganddrop/puzzle/puzzle.pro
new file mode 100644
index 0000000000..cb78a1da41
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzle.pro
@@ -0,0 +1,29 @@
+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
+
+symbian:{
+ TARGET.UID3 = 0xA000CF65
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ addFile.files = example.jpg
+ addFile.path = .
+ DEPLOYMENT += addFile
+}
+wince*: {
+ addFile.files = example.jpg
+ addFile.path = .
+ DEPLOYMENT += addFile
+}
diff --git a/examples/draganddrop/puzzle/puzzle.qrc b/examples/draganddrop/puzzle/puzzle.qrc
new file mode 100644
index 0000000000..4076cec026
--- /dev/null
+++ b/examples/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/draganddrop/puzzle/puzzlewidget.cpp b/examples/draganddrop/puzzle/puzzlewidget.cpp
new file mode 100644
index 0000000000..355c6d55cd
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzlewidget.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "puzzlewidget.h"
+
+PuzzleWidget::PuzzleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setAcceptDrops(true);
+ setMinimumSize(400, 400);
+ setMaximumSize(400, 400);
+}
+
+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.unite(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()/80, square.y()/80)) {
+ 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()/80, square.y()/80))
+ 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()/80, square.y()/80))
+ 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()/80 * 80, position.y()/80 * 80, 80, 80);
+}
diff --git a/examples/draganddrop/puzzle/puzzlewidget.h b/examples/draganddrop/puzzle/puzzlewidget.h
new file mode 100644
index 0000000000..e0356b48fd
--- /dev/null
+++ b/examples/draganddrop/puzzle/puzzlewidget.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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(QWidget *parent = 0);
+ void clear();
+
+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;
+};
+
+#endif
diff --git a/examples/effects/blurpicker/blureffect.cpp b/examples/effects/blurpicker/blureffect.cpp
new file mode 100644
index 0000000000..10410f4669
--- /dev/null
+++ b/examples/effects/blurpicker/blureffect.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/effects/blurpicker/blureffect.h b/examples/effects/blurpicker/blureffect.h
new file mode 100644
index 0000000000..f981b0f4db
--- /dev/null
+++ b/examples/effects/blurpicker/blureffect.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/effects/blurpicker/blurpicker.cpp b/examples/effects/blurpicker/blurpicker.cpp
new file mode 100644
index 0000000000..26e53aafae
--- /dev/null
+++ b/examples/effects/blurpicker/blurpicker.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "blurpicker.h"
+
+#include <QtGui>
+
+#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();
+ }
+}
diff --git a/examples/effects/blurpicker/blurpicker.h b/examples/effects/blurpicker/blurpicker.h
new file mode 100644
index 0000000000..fa5743c70a
--- /dev/null
+++ b/examples/effects/blurpicker/blurpicker.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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);
+
+private:
+ void setupScene();
+
+private:
+ qreal m_index;
+ QList<QGraphicsItem*> m_icons;
+ QPropertyAnimation m_animation;
+};
+
+#endif // BLURPICKER_H
diff --git a/examples/effects/blurpicker/blurpicker.pro b/examples/effects/blurpicker/blurpicker.pro
new file mode 100644
index 0000000000..ba65da8a5c
--- /dev/null
+++ b/examples/effects/blurpicker/blurpicker.pro
@@ -0,0 +1,9 @@
+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
diff --git a/examples/effects/blurpicker/blurpicker.qrc b/examples/effects/blurpicker/blurpicker.qrc
new file mode 100644
index 0000000000..e88eaca966
--- /dev/null
+++ b/examples/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/effects/blurpicker/images/README.txt b/examples/effects/blurpicker/images/README.txt
new file mode 100644
index 0000000000..0927e177d2
--- /dev/null
+++ b/examples/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/effects/blurpicker/images/accessories-calculator.png b/examples/effects/blurpicker/images/accessories-calculator.png
new file mode 100644
index 0000000000..4e7661f65c
--- /dev/null
+++ b/examples/effects/blurpicker/images/accessories-calculator.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/accessories-text-editor.png b/examples/effects/blurpicker/images/accessories-text-editor.png
new file mode 100644
index 0000000000..33bef0bc17
--- /dev/null
+++ b/examples/effects/blurpicker/images/accessories-text-editor.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/background.jpg b/examples/effects/blurpicker/images/background.jpg
new file mode 100644
index 0000000000..e75b38899d
--- /dev/null
+++ b/examples/effects/blurpicker/images/background.jpg
Binary files differ
diff --git a/examples/effects/blurpicker/images/help-browser.png b/examples/effects/blurpicker/images/help-browser.png
new file mode 100644
index 0000000000..8ef4fae91b
--- /dev/null
+++ b/examples/effects/blurpicker/images/help-browser.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/internet-group-chat.png b/examples/effects/blurpicker/images/internet-group-chat.png
new file mode 100644
index 0000000000..dd92d93947
--- /dev/null
+++ b/examples/effects/blurpicker/images/internet-group-chat.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/internet-mail.png b/examples/effects/blurpicker/images/internet-mail.png
new file mode 100644
index 0000000000..7e6b93be83
--- /dev/null
+++ b/examples/effects/blurpicker/images/internet-mail.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/internet-web-browser.png b/examples/effects/blurpicker/images/internet-web-browser.png
new file mode 100644
index 0000000000..a979a92b4f
--- /dev/null
+++ b/examples/effects/blurpicker/images/internet-web-browser.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/office-calendar.png b/examples/effects/blurpicker/images/office-calendar.png
new file mode 100644
index 0000000000..e09590682b
--- /dev/null
+++ b/examples/effects/blurpicker/images/office-calendar.png
Binary files differ
diff --git a/examples/effects/blurpicker/images/system-users.png b/examples/effects/blurpicker/images/system-users.png
new file mode 100644
index 0000000000..a7f630a5bd
--- /dev/null
+++ b/examples/effects/blurpicker/images/system-users.png
Binary files differ
diff --git a/examples/effects/blurpicker/main.cpp b/examples/effects/blurpicker/main.cpp
new file mode 100644
index 0000000000..e95b7e0239
--- /dev/null
+++ b/examples/effects/blurpicker/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/effects/effects.pro b/examples/effects/effects.pro
new file mode 100644
index 0000000000..4b13387902
--- /dev/null
+++ b/examples/effects/effects.pro
@@ -0,0 +1,13 @@
+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
+
diff --git a/examples/effects/fademessage/README.txt b/examples/effects/fademessage/README.txt
new file mode 100644
index 0000000000..f639e76508
--- /dev/null
+++ b/examples/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/effects/fademessage/background.jpg b/examples/effects/fademessage/background.jpg
new file mode 100644
index 0000000000..9884233a29
--- /dev/null
+++ b/examples/effects/fademessage/background.jpg
Binary files differ
diff --git a/examples/effects/fademessage/fademessage.cpp b/examples/effects/fademessage/fademessage.cpp
new file mode 100644
index 0000000000..88f9f89f1b
--- /dev/null
+++ b/examples/effects/fademessage/fademessage.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fademessage.h"
+
+#include <QtGui>
+
+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, 400, 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 * 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/effects/fademessage/fademessage.h b/examples/effects/fademessage/fademessage.h
new file mode 100644
index 0000000000..61e67b1a63
--- /dev/null
+++ b/examples/effects/fademessage/fademessage.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/effects/fademessage/fademessage.pro b/examples/effects/fademessage/fademessage.pro
new file mode 100644
index 0000000000..9cff9a1dfa
--- /dev/null
+++ b/examples/effects/fademessage/fademessage.pro
@@ -0,0 +1,16 @@
+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
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/effects/fademessage
+
+DEPLOYMENT_PLUGIN += qjpeg
+
diff --git a/examples/effects/fademessage/fademessage.qrc b/examples/effects/fademessage/fademessage.qrc
new file mode 100644
index 0000000000..9efea6a67d
--- /dev/null
+++ b/examples/effects/fademessage/fademessage.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>background.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/effects/fademessage/main.cpp b/examples/effects/fademessage/main.cpp
new file mode 100644
index 0000000000..83d6d8eab8
--- /dev/null
+++ b/examples/effects/fademessage/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/effects/lighting/lighting.cpp b/examples/effects/lighting/lighting.cpp
new file mode 100644
index 0000000000..a988ffbcb3
--- /dev/null
+++ b/examples/effects/lighting/lighting.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "lighting.h"
+
+#include <QtGui>
+
+#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();
+}
+
diff --git a/examples/effects/lighting/lighting.h b/examples/effects/lighting/lighting.h
new file mode 100644
index 0000000000..6a6bc56582
--- /dev/null
+++ b/examples/effects/lighting/lighting.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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();
+
+private:
+ qreal angle;
+ QGraphicsScene m_scene;
+ QGraphicsItem *m_lightSource;
+ QList<QGraphicsItem*> m_items;
+};
+
+#endif // LIGHTING_H
diff --git a/examples/effects/lighting/lighting.pro b/examples/effects/lighting/lighting.pro
new file mode 100644
index 0000000000..fd2288640d
--- /dev/null
+++ b/examples/effects/lighting/lighting.pro
@@ -0,0 +1,8 @@
+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
diff --git a/examples/effects/lighting/main.cpp b/examples/effects/lighting/main.cpp
new file mode 100644
index 0000000000..c75d84159f
--- /dev/null
+++ b/examples/effects/lighting/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/examples.pro b/examples/examples.pro
new file mode 100644
index 0000000000..968740d0e5
--- /dev/null
+++ b/examples/examples.pro
@@ -0,0 +1,77 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ network \
+ statemachine \
+ threads \
+ xml
+
+!contains(QT_CONFIG, no-gui) {
+ SUBDIRS += \
+ animation \
+ desktop \
+ dialogs \
+ draganddrop \
+ effects \
+ graphicsview \
+ ipc \
+ itemviews \
+ layouts \
+ linguist \
+ mainwindows \
+ painting \
+ richtext \
+ scroller \
+ sql \
+ tools \
+ tutorials \
+ widgets \
+ uitools \
+ touch \
+ gestures
+}
+
+contains(QT_CONFIG, webkit):SUBDIRS += webkit
+
+symbian: SUBDIRS = \
+ graphicsview \
+ itemviews \
+ network \
+ painting \
+ widgets \
+ draganddrop \
+ mainwindows \
+ sql \
+ uitools \
+ animation \
+ gestures \
+ xml
+
+!contains(QT_CONFIG, no-gui):contains(QT_CONFIG, multimedia) {
+ SUBDIRS += multimedia
+}
+
+contains(QT_CONFIG, script): SUBDIRS += script
+
+contains(QT_CONFIG, phonon):!static: SUBDIRS += phonon
+embedded:SUBDIRS += qws
+!wince*:!symbian: {
+ !contains(QT_EDITION, Console):!contains(QT_CONFIG, no-gui):contains(QT_BUILD_PARTS, tools):SUBDIRS += designer
+ contains(QT_BUILD_PARTS, tools):!contains(QT_CONFIG, no-gui):SUBDIRS += qtestlib help
+} else {
+ contains(QT_BUILD_PARTS, tools):!contains(QT_CONFIG, no-gui):SUBDIRS += qtestlib
+}
+contains(QT_CONFIG, opengl): SUBDIRS += opengl
+contains(QT_CONFIG, openvg): SUBDIRS += openvg
+contains(QT_CONFIG, dbus): SUBDIRS += dbus
+contains(QT_CONFIG, declarative): SUBDIRS += declarative
+win32: SUBDIRS += activeqt
+contains(QT_CONFIG, xmlpatterns):!contains(QT_CONFIG, no-gui): SUBDIRS += xmlpatterns
+contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows
+contains(QT_CONFIG, concurrent): SUBDIRS += qtconcurrent
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/gestures/gestures.pro b/examples/gestures/gestures.pro
new file mode 100644
index 0000000000..1e9e2270f3
--- /dev/null
+++ b/examples/gestures/gestures.pro
@@ -0,0 +1,10 @@
+TEMPLATE = \
+ subdirs
+SUBDIRS = \
+ imagegestures
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/gestures
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS gestures.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/gestures
+INSTALLS += target sources
diff --git a/examples/gestures/imagegestures/imagegestures.pro b/examples/gestures/imagegestures/imagegestures.pro
new file mode 100644
index 0000000000..10326e658d
--- /dev/null
+++ b/examples/gestures/imagegestures/imagegestures.pro
@@ -0,0 +1,21 @@
+HEADERS = imagewidget.h \
+ mainwidget.h
+SOURCES = imagewidget.cpp \
+ main.cpp \
+ mainwidget.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/gestures/imagegestures
+sources.files = $$SOURCES \
+ $$HEADERS \
+ $$RESOURCES \
+ $$FORMS \
+ imagegestures.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/gestures/imagegestures
+INSTALLS += target \
+ sources
+
+symbian {
+ TARGET.UID3 = 0xA000D7D0
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp
new file mode 100644
index 0000000000..8bbb96563e
--- /dev/null
+++ b/examples/gestures/imagegestures/imagewidget.cpp
@@ -0,0 +1,267 @@
+
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "imagewidget.h"
+
+#include <QtGui>
+
+//! [constructor]
+ImageWidget::ImageWidget(QWidget *parent)
+ : QWidget(parent),
+ position(0),
+ horizontalOffset(0),
+ verticalOffset(0),
+ rotationAngle(0),
+ scaleFactor(1),
+ currentStepScaleFactor(1)
+
+{
+ setMinimumSize(QSize(100,100));
+
+//! [enable gestures]
+ grabGesture(Qt::PanGesture);
+ grabGesture(Qt::PinchGesture);
+ grabGesture(Qt::SwipeGesture);
+//! [enable gestures]
+}
+//! [constructor]
+
+//! [event handler]
+bool ImageWidget::event(QEvent *event)
+{
+ if (event->type() == QEvent::Gesture)
+ return gestureEvent(static_cast<QGestureEvent*>(event));
+ return QWidget::event(event);
+}
+//! [event handler]
+
+void ImageWidget::paintEvent(QPaintEvent*)
+{
+ QPainter p(this);
+
+ float iw = currentImage.width();
+ float ih = currentImage.height();
+ float wh = height();
+ float ww = width();
+
+ p.translate(ww/2, wh/2);
+ p.translate(horizontalOffset, verticalOffset);
+ p.rotate(rotationAngle);
+ p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor);
+ p.translate(-iw/2, -ih/2);
+ p.drawImage(0, 0, currentImage);
+}
+
+void ImageWidget::mouseDoubleClickEvent(QMouseEvent *)
+{
+ rotationAngle = 0;
+ scaleFactor = 1;
+ currentStepScaleFactor = 1;
+ verticalOffset = 0;
+ horizontalOffset = 0;
+ update();
+}
+
+//! [gesture event handler]
+bool ImageWidget::gestureEvent(QGestureEvent *event)
+{
+ if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
+ swipeTriggered(static_cast<QSwipeGesture *>(swipe));
+ else if (QGesture *pan = event->gesture(Qt::PanGesture))
+ panTriggered(static_cast<QPanGesture *>(pan));
+ if (QGesture *pinch = event->gesture(Qt::PinchGesture))
+ pinchTriggered(static_cast<QPinchGesture *>(pinch));
+ return true;
+}
+//! [gesture event handler]
+
+void ImageWidget::panTriggered(QPanGesture *gesture)
+{
+#ifndef QT_NO_CURSOR
+ switch (gesture->state()) {
+ case Qt::GestureStarted:
+ case Qt::GestureUpdated:
+ setCursor(Qt::SizeAllCursor);
+ break;
+ default:
+ setCursor(Qt::ArrowCursor);
+ }
+#endif
+ QPointF delta = gesture->delta();
+ horizontalOffset += delta.x();
+ verticalOffset += delta.y();
+ update();
+}
+
+void ImageWidget::pinchTriggered(QPinchGesture *gesture)
+{
+ QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags();
+ if (changeFlags & QPinchGesture::RotationAngleChanged) {
+ qreal value = gesture->property("rotationAngle").toReal();
+ qreal lastValue = gesture->property("lastRotationAngle").toReal();
+ rotationAngle += value - lastValue;
+ }
+ if (changeFlags & QPinchGesture::ScaleFactorChanged) {
+ qreal value = gesture->property("scaleFactor").toReal();
+ currentStepScaleFactor = value;
+ }
+ if (gesture->state() == Qt::GestureFinished) {
+ scaleFactor *= currentStepScaleFactor;
+ currentStepScaleFactor = 1;
+ }
+ update();
+}
+
+//! [swipe function]
+void ImageWidget::swipeTriggered(QSwipeGesture *gesture)
+{
+ if (gesture->state() == Qt::GestureFinished) {
+ if (gesture->horizontalDirection() == QSwipeGesture::Left
+ || gesture->verticalDirection() == QSwipeGesture::Up)
+ goPrevImage();
+ else
+ goNextImage();
+ update();
+ }
+}
+//! [swipe function]
+
+void ImageWidget::resizeEvent(QResizeEvent*)
+{
+ update();
+}
+
+void ImageWidget::openDirectory(const QString &path)
+{
+ this->path = path;
+ QDir dir(path);
+ QStringList nameFilters;
+ nameFilters << "*.jpg" << "*.png";
+ files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
+
+ position = 0;
+ goToImage(0);
+ update();
+}
+
+QImage ImageWidget::loadImage(const QString &fileName)
+{
+ QImageReader reader(fileName);
+ if (!reader.canRead()) {
+ qDebug() << fileName << ": can't load image";
+ return QImage();
+ }
+
+ QImage image;
+ if (!reader.read(&image)) {
+ qDebug() << fileName << ": corrupted image";
+ return QImage();
+ }
+ return image;
+}
+
+void ImageWidget::goNextImage()
+{
+ if (files.isEmpty())
+ return;
+
+ if (position < files.size()-1) {
+ ++position;
+ prevImage = currentImage;
+ currentImage = nextImage;
+ if (position+1 < files.size())
+ nextImage = loadImage(path+QLatin1String("/")+files.at(position+1));
+ else
+ nextImage = QImage();
+ }
+ update();
+}
+
+void ImageWidget::goPrevImage()
+{
+ if (files.isEmpty())
+ return;
+
+ if (position > 0) {
+ --position;
+ nextImage = currentImage;
+ currentImage = prevImage;
+ if (position > 0)
+ prevImage = loadImage(path+QLatin1String("/")+files.at(position-1));
+ else
+ prevImage = QImage();
+ }
+ update();
+}
+
+void ImageWidget::goToImage(int index)
+{
+ if (files.isEmpty())
+ return;
+
+ if (index < 0 || index >= files.size()) {
+ qDebug() << "goToImage: invalid index: " << index;
+ return;
+ }
+
+ if (index == position+1) {
+ goNextImage();
+ return;
+ }
+
+ if (position > 0 && index == position-1) {
+ goPrevImage();
+ return;
+ }
+
+ position = index;
+
+ if (index > 0)
+ prevImage = loadImage(path+QLatin1String("/")+files.at(position-1));
+ else
+ prevImage = QImage();
+ currentImage = loadImage(path+QLatin1String("/")+files.at(position));
+ if (position+1 < files.size())
+ nextImage = loadImage(path+QLatin1String("/")+files.at(position+1));
+ else
+ nextImage = QImage();
+ update();
+}
diff --git a/examples/gestures/imagegestures/imagewidget.h b/examples/gestures/imagegestures/imagewidget.h
new file mode 100644
index 0000000000..fff24fbcdf
--- /dev/null
+++ b/examples/gestures/imagegestures/imagewidget.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGEWIDGET_H
+#define IMAGEWIDGET_H
+
+#include <QWidget>
+#include <QImage>
+#include <QtGui>
+
+QT_BEGIN_NAMESPACE
+class QGestureEvent;
+class QPanGesture;
+class QPinchGesture;
+class QSwipeGesture;
+QT_END_NAMESPACE
+
+//! [class definition begin]
+class ImageWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ImageWidget(QWidget *parent = 0);
+ void openDirectory(const QString &path);
+
+protected:
+ bool event(QEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ void mouseDoubleClickEvent(QMouseEvent *event);
+
+private:
+ bool gestureEvent(QGestureEvent *event);
+ void panTriggered(QPanGesture*);
+ void pinchTriggered(QPinchGesture*);
+ void swipeTriggered(QSwipeGesture*);
+//! [class definition begin]
+
+ void updateImage();
+ QImage loadImage(const QString &fileName);
+ void loadImage();
+ void goNextImage();
+ void goPrevImage();
+ void goToImage(int index);
+
+ QString path;
+ QStringList files;
+ int position;
+
+ QImage prevImage, nextImage;
+ QImage currentImage;
+
+ float horizontalOffset;
+ float verticalOffset;
+ float rotationAngle;
+ float scaleFactor;
+ float currentStepScaleFactor;
+//! [class definition end]
+};
+//! [class definition end]
+
+#endif
diff --git a/examples/gestures/imagegestures/main.cpp b/examples/gestures/imagegestures/main.cpp
new file mode 100644
index 0000000000..ca37a733f7
--- /dev/null
+++ b/examples/gestures/imagegestures/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwidget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ MainWidget w;
+ w.show();
+
+ if (QApplication::arguments().size() > 1)
+ w.openDirectory(QApplication::arguments().at(1));
+ else
+ w.openDirectory(QFileDialog::getExistingDirectory(0, "Select image folder"));
+
+ return app.exec();
+}
diff --git a/examples/gestures/imagegestures/mainwidget.cpp b/examples/gestures/imagegestures/mainwidget.cpp
new file mode 100644
index 0000000000..329cfe3bfd
--- /dev/null
+++ b/examples/gestures/imagegestures/mainwidget.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "imagewidget.h"
+#include "mainwidget.h"
+
+MainWidget::MainWidget(QWidget *parent)
+ : QMainWindow(parent)
+{
+ resize(400, 300);
+ imageWidget = new ImageWidget(this);
+ setCentralWidget(imageWidget);
+}
+
+void MainWidget::openDirectory(const QString &path)
+{
+ imageWidget->openDirectory(path);
+}
diff --git a/examples/gestures/imagegestures/mainwidget.h b/examples/gestures/imagegestures/mainwidget.h
new file mode 100644
index 0000000000..066b1ee680
--- /dev/null
+++ b/examples/gestures/imagegestures/mainwidget.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWIDGET_H
+#define MAINWIDGET_H
+
+#include <QMainWindow>
+
+class ImageWidget;
+
+class MainWidget : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWidget(QWidget *parent = 0);
+
+public slots:
+ void openDirectory(const QString &path);
+
+private:
+ bool loadImage(const QString &fileName);
+
+ ImageWidget *imageWidget;
+};
+
+#endif
diff --git a/examples/graphicsview/README b/examples/graphicsview/README
new file mode 100644
index 0000000000..6c38c18683
--- /dev/null
+++ b/examples/graphicsview/README
@@ -0,0 +1,40 @@
+Qt is provided with a comprehensive canvas through the GraphicsView
+classes.
+
+These examples demonstrate the fundamental aspects of canvas programming
+with Qt.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/graphicsview/anchorlayout/anchorlayout.pro b/examples/graphicsview/anchorlayout/anchorlayout.pro
new file mode 100644
index 0000000000..52cb13b241
--- /dev/null
+++ b/examples/graphicsview/anchorlayout/anchorlayout.pro
@@ -0,0 +1,9 @@
+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
diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp
new file mode 100644
index 0000000000..c31afd214d
--- /dev/null
+++ b/examples/graphicsview/anchorlayout/main.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGraphicsWidget>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsAnchorLayout>
+#include <QtGui>
+
+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
+ QGraphicsAnchor *anchor = l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
+ anchor = l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
+
+ anchor = l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
+ anchor = l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
+ anchor = l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
+ anchor = l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
+
+ anchor = l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
+ anchor = l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
+
+ anchor = l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
+ anchor = l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
+ anchor = l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
+ anchor = l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);
+
+ // horizontal
+ anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
+ anchor = l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
+ anchor = l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
+
+ anchor = l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
+ anchor = l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
+
+ anchor = l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
+ anchor = l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
+ anchor = l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
+
+ anchor = l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
+ anchor = l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
+ anchor = 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/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
new file mode 100644
index 0000000000..f23bb7544d
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro
@@ -0,0 +1,17 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A645
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc
new file mode 100644
index 0000000000..fbe2efa572
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource>
+ <file>images/block.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/graphicsview/basicgraphicslayouts/images/block.png b/examples/graphicsview/basicgraphicslayouts/images/block.png
new file mode 100644
index 0000000000..4c72a3f508
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/images/block.png
Binary files differ
diff --git a/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp b/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp
new file mode 100644
index 0000000000..0b1a10dd50
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/graphicsview/basicgraphicslayouts/layoutitem.h
new file mode 100644
index 0000000000..448e9bac3f
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+
+//! [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/graphicsview/basicgraphicslayouts/main.cpp b/examples/graphicsview/basicgraphicslayouts/main.cpp
new file mode 100644
index 0000000000..57448a58d7
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/graphicsview/basicgraphicslayouts/window.cpp b/examples/graphicsview/basicgraphicslayouts/window.cpp
new file mode 100644
index 0000000000..17a456e240
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/window.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/basicgraphicslayouts/window.h b/examples/graphicsview/basicgraphicslayouts/window.h
new file mode 100644
index 0000000000..b2166f0552
--- /dev/null
+++ b/examples/graphicsview/basicgraphicslayouts/window.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QtGui/QGraphicsWidget>
+
+//! [0]
+class Window : public QGraphicsWidget {
+ Q_OBJECT
+
+public:
+ Window(QGraphicsWidget *parent = 0);
+
+};
+//! [0]
+
+#endif //WINDOW_H
+
diff --git a/examples/graphicsview/collidingmice/collidingmice.pro b/examples/graphicsview/collidingmice/collidingmice.pro
new file mode 100644
index 0000000000..c88cf5306f
--- /dev/null
+++ b/examples/graphicsview/collidingmice/collidingmice.pro
@@ -0,0 +1,19 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A643
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/graphicsview/collidingmice/images/cheese.jpg b/examples/graphicsview/collidingmice/images/cheese.jpg
new file mode 100644
index 0000000000..dea5795fd0
--- /dev/null
+++ b/examples/graphicsview/collidingmice/images/cheese.jpg
Binary files differ
diff --git a/examples/graphicsview/collidingmice/main.cpp b/examples/graphicsview/collidingmice/main.cpp
new file mode 100644
index 0000000000..2970a0079f
--- /dev/null
+++ b/examples/graphicsview/collidingmice/main.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mouse.h"
+
+#include <QtGui>
+
+#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/graphicsview/collidingmice/mice.qrc b/examples/graphicsview/collidingmice/mice.qrc
new file mode 100644
index 0000000000..accdb4d0a6
--- /dev/null
+++ b/examples/graphicsview/collidingmice/mice.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/cheese.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/graphicsview/collidingmice/mouse.cpp b/examples/graphicsview/collidingmice/mouse.cpp
new file mode 100644
index 0000000000..4e89454f8d
--- /dev/null
+++ b/examples/graphicsview/collidingmice/mouse.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/collidingmice/mouse.h b/examples/graphicsview/collidingmice/mouse.h
new file mode 100644
index 0000000000..430e741d5b
--- /dev/null
+++ b/examples/graphicsview/collidingmice/mouse.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/diagramscene/arrow.cpp b/examples/graphicsview/diagramscene/arrow.cpp
new file mode 100644
index 0000000000..188928d1d8
--- /dev/null
+++ b/examples/graphicsview/diagramscene/arrow.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "arrow.h"
+#include <math.h>
+
+const qreal Pi = 3.14;
+
+//! [0]
+Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem,
+ QGraphicsItem *parent, QGraphicsScene *scene)
+ : QGraphicsLineItem(parent, scene)
+{
+ 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/graphicsview/diagramscene/arrow.h b/examples/graphicsview/diagramscene/arrow.h
new file mode 100644
index 0000000000..cc6ff9732d
--- /dev/null
+++ b/examples/graphicsview/diagramscene/arrow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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, QGraphicsScene *scene = 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/graphicsview/diagramscene/diagramitem.cpp b/examples/graphicsview/diagramscene/diagramitem.cpp
new file mode 100644
index 0000000000..cd7ce0c6e1
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramitem.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "diagramitem.h"
+#include "arrow.h"
+
+//! [0]
+DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
+ QGraphicsItem *parent, QGraphicsScene *scene)
+ : QGraphicsPolygonItem(parent, scene)
+{
+ 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/graphicsview/diagramscene/diagramitem.h b/examples/graphicsview/diagramscene/diagramitem.h
new file mode 100644
index 0000000000..44a8b6dad5
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramitem.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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, QGraphicsScene *scene = 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/graphicsview/diagramscene/diagramscene.cpp b/examples/graphicsview/diagramscene/diagramscene.cpp
new file mode 100644
index 0000000000..7592224db7
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramscene.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/graphicsview/diagramscene/diagramscene.h b/examples/graphicsview/diagramscene/diagramscene.h
new file mode 100644
index 0000000000..4ebe1d2a71
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramscene.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/diagramscene/diagramscene.pro b/examples/graphicsview/diagramscene/diagramscene.pro
new file mode 100644
index 0000000000..02660b1427
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramscene.pro
@@ -0,0 +1,22 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/graphicsview/diagramscene/diagramscene.qrc b/examples/graphicsview/diagramscene/diagramscene.qrc
new file mode 100644
index 0000000000..a11158402f
--- /dev/null
+++ b/examples/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/graphicsview/diagramscene/diagramtextitem.cpp b/examples/graphicsview/diagramscene/diagramtextitem.cpp
new file mode 100644
index 0000000000..588603eda5
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramtextitem.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "diagramtextitem.h"
+#include "diagramscene.h"
+
+//! [0]
+DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene)
+ : QGraphicsTextItem(parent, scene)
+{
+ 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/graphicsview/diagramscene/diagramtextitem.h b/examples/graphicsview/diagramscene/diagramtextitem.h
new file mode 100644
index 0000000000..5e3505f6f0
--- /dev/null
+++ b/examples/graphicsview/diagramscene/diagramtextitem.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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, QGraphicsScene *scene = 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/graphicsview/diagramscene/images/background1.png b/examples/graphicsview/diagramscene/images/background1.png
new file mode 100644
index 0000000000..0f93c6bf42
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/background1.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/background2.png b/examples/graphicsview/diagramscene/images/background2.png
new file mode 100644
index 0000000000..1e293db67a
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/background2.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/background3.png b/examples/graphicsview/diagramscene/images/background3.png
new file mode 100644
index 0000000000..3db4f8ea5f
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/background3.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/background4.png b/examples/graphicsview/diagramscene/images/background4.png
new file mode 100644
index 0000000000..9c1f3bfd77
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/background4.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/bold.png b/examples/graphicsview/diagramscene/images/bold.png
new file mode 100644
index 0000000000..986e65e250
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/bold.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/bringtofront.png b/examples/graphicsview/diagramscene/images/bringtofront.png
new file mode 100644
index 0000000000..bda27578a2
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/bringtofront.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/delete.png b/examples/graphicsview/diagramscene/images/delete.png
new file mode 100644
index 0000000000..df2a147d24
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/delete.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/floodfill.png b/examples/graphicsview/diagramscene/images/floodfill.png
new file mode 100644
index 0000000000..54c0dae237
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/floodfill.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/italic.png b/examples/graphicsview/diagramscene/images/italic.png
new file mode 100644
index 0000000000..9a438b57ad
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/italic.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/linecolor.png b/examples/graphicsview/diagramscene/images/linecolor.png
new file mode 100644
index 0000000000..98a821f27e
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/linecolor.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/linepointer.png b/examples/graphicsview/diagramscene/images/linepointer.png
new file mode 100644
index 0000000000..66933d43b3
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/linepointer.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/pointer.png b/examples/graphicsview/diagramscene/images/pointer.png
new file mode 100644
index 0000000000..0b0b0aa69d
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/pointer.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/sendtoback.png b/examples/graphicsview/diagramscene/images/sendtoback.png
new file mode 100644
index 0000000000..5aa3b0a243
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/sendtoback.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/textpointer.png b/examples/graphicsview/diagramscene/images/textpointer.png
new file mode 100644
index 0000000000..b25832cada
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/textpointer.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/images/underline.png b/examples/graphicsview/diagramscene/images/underline.png
new file mode 100644
index 0000000000..9b8209f525
--- /dev/null
+++ b/examples/graphicsview/diagramscene/images/underline.png
Binary files differ
diff --git a/examples/graphicsview/diagramscene/main.cpp b/examples/graphicsview/diagramscene/main.cpp
new file mode 100644
index 0000000000..fcd027cb44
--- /dev/null
+++ b/examples/graphicsview/diagramscene/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/graphicsview/diagramscene/mainwindow.cpp b/examples/graphicsview/diagramscene/mainwindow.cpp
new file mode 100644
index 0000000000..87eb33e7ee
--- /dev/null
+++ b/examples/graphicsview/diagramscene/mainwindow.cpp
@@ -0,0 +1,662 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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();
+ QColor color = textItem->defaultTextColor();
+ 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/graphicsview/diagramscene/mainwindow.h b/examples/graphicsview/diagramscene/mainwindow.h
new file mode 100644
index 0000000000..ad76395a69
--- /dev/null
+++ b/examples/graphicsview/diagramscene/mainwindow.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/dragdroprobot/coloritem.cpp b/examples/graphicsview/dragdroprobot/coloritem.cpp
new file mode 100644
index 0000000000..81e8f5607b
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/coloritem.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/graphicsview/dragdroprobot/coloritem.h b/examples/graphicsview/dragdroprobot/coloritem.h
new file mode 100644
index 0000000000..e5874f910d
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/coloritem.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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/graphicsview/dragdroprobot/dragdroprobot.pro b/examples/graphicsview/dragdroprobot/dragdroprobot.pro
new file mode 100644
index 0000000000..736958baa1
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/dragdroprobot.pro
@@ -0,0 +1,20 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/graphicsview/dragdroprobot/images/head.png b/examples/graphicsview/dragdroprobot/images/head.png
new file mode 100644
index 0000000000..1e520e09b8
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/images/head.png
Binary files differ
diff --git a/examples/graphicsview/dragdroprobot/main.cpp b/examples/graphicsview/dragdroprobot/main.cpp
new file mode 100644
index 0000000000..315d2b6917
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/main.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "coloritem.h"
+#include "robot.h"
+
+#include <math.h>
+
+//! [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->scale(1.2, 1.2);
+ robot->setPos(0, -20);
+ scene.addItem(robot);
+//! [1]
+//! [2]
+ QGraphicsView 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/graphicsview/dragdroprobot/robot.cpp b/examples/graphicsview/dragdroprobot/robot.cpp
new file mode 100644
index 0000000000..9494e7af7f
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/robot.cpp
@@ -0,0 +1,307 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/graphicsview/dragdroprobot/robot.h b/examples/graphicsview/dragdroprobot/robot.h
new file mode 100644
index 0000000000..e65f39426b
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/robot.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/dragdroprobot/robot.qrc b/examples/graphicsview/dragdroprobot/robot.qrc
new file mode 100644
index 0000000000..b0969d2a64
--- /dev/null
+++ b/examples/graphicsview/dragdroprobot/robot.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/head.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp
new file mode 100644
index 0000000000..2b5cae5e1b
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/edge.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/elasticnodes/edge.h b/examples/graphicsview/elasticnodes/edge.h
new file mode 100644
index 0000000000..8f73edd787
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/edge.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/elasticnodes/elasticnodes.pro b/examples/graphicsview/elasticnodes/elasticnodes.pro
new file mode 100644
index 0000000000..cb7cc1b928
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/elasticnodes.pro
@@ -0,0 +1,23 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A642
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/graphicsview/elasticnodes/graphwidget.cpp b/examples/graphicsview/elasticnodes/graphwidget.cpp
new file mode 100644
index 0000000000..c875b6551d
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/graphwidget.cpp
@@ -0,0 +1,235 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphwidget.h"
+#include "edge.h"
+#include "node.h"
+
+#include <QtGui>
+
+#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:
+ scaleView(qreal(1.2));
+ break;
+ case Qt::Key_Minus:
+ scaleView(1 / qreal(1.2));
+ break;
+ case Qt::Key_Space:
+ case Qt::Key_Enter:
+ foreach (QGraphicsItem *item, scene()->items()) {
+ if (qgraphicsitem_cast<Node *>(item))
+ item->setPos(-150 + qrand() % 300, -150 + qrand() % 300);
+ }
+ 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.intersect(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]
diff --git a/examples/graphicsview/elasticnodes/graphwidget.h b/examples/graphicsview/elasticnodes/graphwidget.h
new file mode 100644
index 0000000000..764bb3f0b9
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/graphwidget.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GRAPHWIDGET_H
+#define GRAPHWIDGET_H
+
+#include <QtGui/QGraphicsView>
+
+class Node;
+
+//! [0]
+class GraphWidget : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ GraphWidget(QWidget *parent = 0);
+
+ void itemMoved();
+
+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/graphicsview/elasticnodes/main.cpp b/examples/graphicsview/elasticnodes/main.cpp
new file mode 100644
index 0000000000..ab7e7cf7c7
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "graphwidget.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ GraphWidget widget;
+ widget.show();
+ return app.exec();
+}
diff --git a/examples/graphicsview/elasticnodes/node.cpp b/examples/graphicsview/elasticnodes/node.cpp
new file mode 100644
index 0000000000..8d1daddc12
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/node.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/elasticnodes/node.h b/examples/graphicsview/elasticnodes/node.h
new file mode 100644
index 0000000000..53af7182d0
--- /dev/null
+++ b/examples/graphicsview/elasticnodes/node.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/flowlayout/flowlayout.cpp b/examples/graphicsview/flowlayout/flowlayout.cpp
new file mode 100644
index 0000000000..0531e4cce5
--- /dev/null
+++ b/examples/graphicsview/flowlayout/flowlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flowlayout.h"
+#include <QtGui/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/graphicsview/flowlayout/flowlayout.h b/examples/graphicsview/flowlayout/flowlayout.h
new file mode 100644
index 0000000000..aff3382c01
--- /dev/null
+++ b/examples/graphicsview/flowlayout/flowlayout.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/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/graphicsview/flowlayout/flowlayout.pro b/examples/graphicsview/flowlayout/flowlayout.pro
new file mode 100644
index 0000000000..ce3536774b
--- /dev/null
+++ b/examples/graphicsview/flowlayout/flowlayout.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QMAKE_PROJECT_NAME = flowlayout_graphicsview
+
+# Input
+HEADERS += flowlayout.h window.h
+SOURCES += flowlayout.cpp main.cpp window.cpp
diff --git a/examples/graphicsview/flowlayout/main.cpp b/examples/graphicsview/flowlayout/main.cpp
new file mode 100644
index 0000000000..cee08d76ac
--- /dev/null
+++ b/examples/graphicsview/flowlayout/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/graphicsview/flowlayout/window.cpp b/examples/graphicsview/flowlayout/window.cpp
new file mode 100644
index 0000000000..4abe2a55c2
--- /dev/null
+++ b/examples/graphicsview/flowlayout/window.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/qgraphicsproxywidget.h>
+#include <QtGui/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/graphicsview/flowlayout/window.h b/examples/graphicsview/flowlayout/window.h
new file mode 100644
index 0000000000..c338a14236
--- /dev/null
+++ b/examples/graphicsview/flowlayout/window.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/qgraphicswidget.h>
+
+class Window : public QGraphicsWidget {
+ Q_OBJECT
+public:
+ Window();
+};
diff --git a/examples/graphicsview/graphicsview.pro b/examples/graphicsview/graphicsview.pro
new file mode 100644
index 0000000000..5e49855104
--- /dev/null
+++ b/examples/graphicsview/graphicsview.pro
@@ -0,0 +1,25 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ elasticnodes \
+ collidingmice \
+ padnavigator \
+ basicgraphicslayouts
+
+!symbian: SUBDIRS += \
+ diagramscene \
+ dragdroprobot \
+ flowlayout \
+ anchorlayout \
+ simpleanchorlayout \
+ weatheranchorlayout
+
+contains(QT_CONFIG, qt3support):SUBDIRS += portedcanvas portedasteroids
+contains(DEFINES, QT_NO_CURSOR)|contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= dragdroprobot
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/graphicsview/padnavigator/flippablepad.cpp b/examples/graphicsview/padnavigator/flippablepad.cpp
new file mode 100644
index 0000000000..ada44dad8f
--- /dev/null
+++ b/examples/graphicsview/padnavigator/flippablepad.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flippablepad.h"
+
+#include <QtGui/QtGui>
+
+//! [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/graphicsview/padnavigator/flippablepad.h b/examples/graphicsview/padnavigator/flippablepad.h
new file mode 100644
index 0000000000..0114b43a75
--- /dev/null
+++ b/examples/graphicsview/padnavigator/flippablepad.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/padnavigator/form.ui b/examples/graphicsview/padnavigator/form.ui
new file mode 100644
index 0000000000..fc7d12321e
--- /dev/null
+++ b/examples/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/graphicsview/padnavigator/images/artsfftscope.png b/examples/graphicsview/padnavigator/images/artsfftscope.png
new file mode 100644
index 0000000000..4db003f8d2
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/artsfftscope.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/blue_angle_swirl.jpg b/examples/graphicsview/padnavigator/images/blue_angle_swirl.jpg
new file mode 100644
index 0000000000..5bf0debdbd
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/blue_angle_swirl.jpg
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/kontact_contacts.png b/examples/graphicsview/padnavigator/images/kontact_contacts.png
new file mode 100644
index 0000000000..6fb4cc8f38
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/kontact_contacts.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/kontact_journal.png b/examples/graphicsview/padnavigator/images/kontact_journal.png
new file mode 100644
index 0000000000..b1fedb6982
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/kontact_journal.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/kontact_mail.png b/examples/graphicsview/padnavigator/images/kontact_mail.png
new file mode 100644
index 0000000000..672f8fa3ab
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/kontact_mail.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/kontact_notes.png b/examples/graphicsview/padnavigator/images/kontact_notes.png
new file mode 100644
index 0000000000..229bf73ac6
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/kontact_notes.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/kopeteavailable.png b/examples/graphicsview/padnavigator/images/kopeteavailable.png
new file mode 100644
index 0000000000..2eaf41afec
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/kopeteavailable.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/metacontact_online.png b/examples/graphicsview/padnavigator/images/metacontact_online.png
new file mode 100644
index 0000000000..6a398dd10f
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/metacontact_online.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/images/minitools.png b/examples/graphicsview/padnavigator/images/minitools.png
new file mode 100644
index 0000000000..0248c9d50a
--- /dev/null
+++ b/examples/graphicsview/padnavigator/images/minitools.png
Binary files differ
diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp
new file mode 100644
index 0000000000..8f4a681743
--- /dev/null
+++ b/examples/graphicsview/padnavigator/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "padnavigator.h"
+
+#include <QtGui/QtGui>
+
+//! [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/graphicsview/padnavigator/padnavigator.cpp b/examples/graphicsview/padnavigator/padnavigator.cpp
new file mode 100644
index 0000000000..3e57dcfbe6
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.cpp
@@ -0,0 +1,306 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "flippablepad.h"
+#include "padnavigator.h"
+#include "splashitem.h"
+
+#include <QtGui/QtGui>
+#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/graphicsview/padnavigator/padnavigator.h b/examples/graphicsview/padnavigator/padnavigator.h
new file mode 100644
index 0000000000..0fcfde931f
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/padnavigator/padnavigator.pro b/examples/graphicsview/padnavigator/padnavigator.pro
new file mode 100644
index 0000000000..de492f3e9e
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.pro
@@ -0,0 +1,32 @@
+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
+
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A644
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/graphicsview/padnavigator/padnavigator.qrc b/examples/graphicsview/padnavigator/padnavigator.qrc
new file mode 100644
index 0000000000..b26ab92ae1
--- /dev/null
+++ b/examples/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/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp
new file mode 100644
index 0000000000..643770f4c6
--- /dev/null
+++ b/examples/graphicsview/padnavigator/roundrectitem.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "roundrectitem.h"
+
+#include <QtGui/QtGui>
+
+//! [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/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h
new file mode 100644
index 0000000000..a7d014f12a
--- /dev/null
+++ b/examples/graphicsview/padnavigator/roundrectitem.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp
new file mode 100644
index 0000000000..8cedcd6e60
--- /dev/null
+++ b/examples/graphicsview/padnavigator/splashitem.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "splashitem.h"
+
+#include <QtGui/QtGui>
+
+//! [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/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h
new file mode 100644
index 0000000000..4d0b58a824
--- /dev/null
+++ b/examples/graphicsview/padnavigator/splashitem.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/graphicsview/simpleanchorlayout/main.cpp b/examples/graphicsview/simpleanchorlayout/main.cpp
new file mode 100644
index 0000000000..4fa837f540
--- /dev/null
+++ b/examples/graphicsview/simpleanchorlayout/main.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+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/graphicsview/simpleanchorlayout/simpleanchorlayout.pro b/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro
new file mode 100644
index 0000000000..f85ad8f3a7
--- /dev/null
+++ b/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro
@@ -0,0 +1,9 @@
+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
diff --git a/examples/graphicsview/weatheranchorlayout/images/5days.jpg b/examples/graphicsview/weatheranchorlayout/images/5days.jpg
new file mode 100644
index 0000000000..fd92ba8ba7
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/5days.jpg
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/images/details.jpg b/examples/graphicsview/weatheranchorlayout/images/details.jpg
new file mode 100644
index 0000000000..fde0448c69
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/details.jpg
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/images/place.jpg b/examples/graphicsview/weatheranchorlayout/images/place.jpg
new file mode 100644
index 0000000000..03e5344330
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/place.jpg
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/images/tabbar.jpg b/examples/graphicsview/weatheranchorlayout/images/tabbar.jpg
new file mode 100644
index 0000000000..7777662901
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/tabbar.jpg
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/images/title.jpg b/examples/graphicsview/weatheranchorlayout/images/title.jpg
new file mode 100644
index 0000000000..fa84c8156c
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/title.jpg
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/images/weather-few-clouds.png b/examples/graphicsview/weatheranchorlayout/images/weather-few-clouds.png
new file mode 100644
index 0000000000..eea6ce6529
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/images/weather-few-clouds.png
Binary files differ
diff --git a/examples/graphicsview/weatheranchorlayout/main.cpp b/examples/graphicsview/weatheranchorlayout/main.cpp
new file mode 100644
index 0000000000..67596ac4bc
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/main.cpp
@@ -0,0 +1,259 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QLabel>
+#include <QPainter>
+#include <QPushButton>
+#include <QApplication>
+
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QGraphicsWidget>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsAnchorLayout>
+#include <QGraphicsSceneResizeEvent>
+
+
+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->scale(rect.width() / r.width(), rect.height() / r.height());
+ 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/graphicsview/weatheranchorlayout/weatheranchorlayout.pro b/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro
new file mode 100644
index 0000000000..57e154e27a
--- /dev/null
+++ b/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro
@@ -0,0 +1,14 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue May 12 15:22:25 2009
+######################################################################
+
+# Input
+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
+
diff --git a/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc b/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.qrc
new file mode 100644
index 0000000000..e39f8c0423
--- /dev/null
+++ b/examples/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/ipc/README b/examples/ipc/README
new file mode 100644
index 0000000000..71e2f46c18
--- /dev/null
+++ b/examples/ipc/README
@@ -0,0 +1,35 @@
+These examples demonstrate IPC support in Qt.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/ipc/ipc.pro b/examples/ipc/ipc.pro
new file mode 100644
index 0000000000..429fde29dc
--- /dev/null
+++ b/examples/ipc/ipc.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+# no QSharedMemory
+!vxworks:!qnx:SUBDIRS = sharedmemory
+!wince*: SUBDIRS += localfortuneserver localfortuneclient
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS ipc.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/ipc/localfortuneclient/client.cpp b/examples/ipc/localfortuneclient/client.cpp
new file mode 100644
index 0000000000..c8c3fe4f35
--- /dev/null
+++ b/examples/ipc/localfortuneclient/client.cpp
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "client.h"
+
+Client::Client(QWidget *parent)
+ : QDialog(parent)
+{
+ hostLabel = new QLabel(tr("&Server name:"));
+ hostLineEdit = new QLineEdit("fortune");
+
+ hostLabel->setBuddy(hostLineEdit);
+
+ statusLabel = new QLabel(tr("This examples requires that you run the "
+ "Fortune Server example as well."));
+
+ getFortuneButton = new QPushButton(tr("Get Fortune"));
+ getFortuneButton->setDefault(true);
+
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ socket = new QLocalSocket(this);
+
+ connect(hostLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(getFortuneButton, SIGNAL(clicked()),
+ this, SLOT(requestNewFortune()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(socket, SIGNAL(readyRead()), this, SLOT(readFortune()));
+ connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
+ this, SLOT(displayError(QLocalSocket::LocalSocketError)));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(hostLabel, 0, 0);
+ mainLayout->addWidget(hostLineEdit, 0, 1);
+ mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Fortune Client"));
+ hostLineEdit->setFocus();
+}
+
+void Client::requestNewFortune()
+{
+ getFortuneButton->setEnabled(false);
+ blockSize = 0;
+ socket->abort();
+ socket->connectToServer(hostLineEdit->text());
+}
+
+void Client::readFortune()
+{
+ QDataStream in(socket);
+ in.setVersion(QDataStream::Qt_4_0);
+
+ if (blockSize == 0) {
+ if (socket->bytesAvailable() < (int)sizeof(quint16))
+ return;
+ in >> blockSize;
+ }
+
+ if (in.atEnd())
+ return;
+
+ QString nextFortune;
+ in >> nextFortune;
+
+ if (nextFortune == currentFortune) {
+ QTimer::singleShot(0, this, SLOT(requestNewFortune()));
+ return;
+ }
+
+ currentFortune = nextFortune;
+ statusLabel->setText(currentFortune);
+ getFortuneButton->setEnabled(true);
+}
+
+void Client::displayError(QLocalSocket::LocalSocketError socketError)
+{
+ switch (socketError) {
+ case QLocalSocket::ServerNotFoundError:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The host was not found. Please check the "
+ "host name and port settings."));
+ break;
+ case QLocalSocket::ConnectionRefusedError:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The connection was refused by the peer. "
+ "Make sure the fortune server is running, "
+ "and check that the host name and port "
+ "settings are correct."));
+ break;
+ case QLocalSocket::PeerClosedError:
+ break;
+ default:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The following error occurred: %1.")
+ .arg(socket->errorString()));
+ }
+
+ getFortuneButton->setEnabled(true);
+}
+
+void Client::enableGetFortuneButton()
+{
+ getFortuneButton->setEnabled(!hostLineEdit->text().isEmpty());
+}
diff --git a/examples/ipc/localfortuneclient/client.h b/examples/ipc/localfortuneclient/client.h
new file mode 100644
index 0000000000..d23db9e6e2
--- /dev/null
+++ b/examples/ipc/localfortuneclient/client.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <QDialog>
+#include <qlocalsocket.h>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QLocalSocket;
+QT_END_NAMESPACE
+
+class Client : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Client(QWidget *parent = 0);
+
+private slots:
+ void requestNewFortune();
+ void readFortune();
+ void displayError(QLocalSocket::LocalSocketError socketError);
+ void enableGetFortuneButton();
+
+private:
+ QLabel *hostLabel;
+ QLineEdit *hostLineEdit;
+ QLabel *statusLabel;
+ QPushButton *getFortuneButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QLocalSocket *socket;
+ QString currentFortune;
+ quint16 blockSize;
+};
+
+#endif
diff --git a/examples/ipc/localfortuneclient/localfortuneclient.pro b/examples/ipc/localfortuneclient/localfortuneclient.pro
new file mode 100644
index 0000000000..914ed75657
--- /dev/null
+++ b/examples/ipc/localfortuneclient/localfortuneclient.pro
@@ -0,0 +1,14 @@
+HEADERS = client.h
+SOURCES = client.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/localfortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS localfortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/localfortuneclient
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+
diff --git a/examples/ipc/localfortuneclient/main.cpp b/examples/ipc/localfortuneclient/main.cpp
new file mode 100644
index 0000000000..19464d1de3
--- /dev/null
+++ b/examples/ipc/localfortuneclient/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "client.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Client client;
+ client.show();
+ return client.exec();
+}
diff --git a/examples/ipc/localfortuneserver/localfortuneserver.pro b/examples/ipc/localfortuneserver/localfortuneserver.pro
new file mode 100644
index 0000000000..1f160f9ec8
--- /dev/null
+++ b/examples/ipc/localfortuneserver/localfortuneserver.pro
@@ -0,0 +1,14 @@
+HEADERS = server.h
+SOURCES = server.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/localfortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS localfortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/localfortuneserver
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+
diff --git a/examples/ipc/localfortuneserver/main.cpp b/examples/ipc/localfortuneserver/main.cpp
new file mode 100644
index 0000000000..6c0e9ee9f3
--- /dev/null
+++ b/examples/ipc/localfortuneserver/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QtCore>
+
+#include <stdlib.h>
+
+#include "server.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Server server;
+ server.show();
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ return server.exec();
+}
diff --git a/examples/ipc/localfortuneserver/server.cpp b/examples/ipc/localfortuneserver/server.cpp
new file mode 100644
index 0000000000..88784d440e
--- /dev/null
+++ b/examples/ipc/localfortuneserver/server.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include <stdlib.h>
+
+#include "server.h"
+#include <qlocalserver.h>
+#include <qlocalsocket.h>
+
+Server::Server(QWidget *parent)
+ : QDialog(parent)
+{
+ statusLabel = new QLabel;
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+ server = new QLocalServer(this);
+ if (!server->listen("fortune")) {
+ QMessageBox::critical(this, tr("Fortune Server"),
+ tr("Unable to start the server: %1.")
+ .arg(server->errorString()));
+ close();
+ return;
+ }
+
+ statusLabel->setText(tr("The server is running.\n"
+ "Run the Fortune Client example now."));
+
+ fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
+ << tr("You've got to think about tomorrow.")
+ << tr("You will be surprised by a loud noise.")
+ << tr("You will feel hungry again in another hour.")
+ << tr("You might have mail.")
+ << tr("You cannot kill time without injuring eternity.")
+ << tr("Computers are not intelligent. They only think they are.");
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(server, SIGNAL(newConnection()), this, SLOT(sendFortune()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Fortune Server"));
+}
+
+void Server::sendFortune()
+{
+ QByteArray block;
+ QDataStream out(&block, QIODevice::WriteOnly);
+ out.setVersion(QDataStream::Qt_4_0);
+ out << (quint16)0;
+ out << fortunes.at(qrand() % fortunes.size());
+ out.device()->seek(0);
+ out << (quint16)(block.size() - sizeof(quint16));
+
+ QLocalSocket *clientConnection = server->nextPendingConnection();
+ connect(clientConnection, SIGNAL(disconnected()),
+ clientConnection, SLOT(deleteLater()));
+
+ clientConnection->write(block);
+ clientConnection->flush();
+ clientConnection->disconnectFromServer();
+}
diff --git a/examples/ipc/localfortuneserver/server.h b/examples/ipc/localfortuneserver/server.h
new file mode 100644
index 0000000000..5f00ba4d2d
--- /dev/null
+++ b/examples/ipc/localfortuneserver/server.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SERVER_H
+#define SERVER_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QLocalServer;
+QT_END_NAMESPACE
+
+class Server : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Server(QWidget *parent = 0);
+
+private slots:
+ void sendFortune();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ QLocalServer *server;
+ QStringList fortunes;
+};
+
+#endif
diff --git a/examples/ipc/sharedmemory/dialog.cpp b/examples/ipc/sharedmemory/dialog.cpp
new file mode 100644
index 0000000000..fd7535ed13
--- /dev/null
+++ b/examples/ipc/sharedmemory/dialog.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "dialog.h"
+#include <QFileDialog>
+#include <QBuffer>
+#include <QtCore/QDebug>
+
+/*!
+ \class Dialog
+
+ \brief This class is a simple example of how to use QSharedMemory.
+
+ It is a simple dialog that presents a few buttons. To compile the
+ example, run make in qt/examples/ipc. Then run the executable twice
+ to create two processes running the dialog. In one of the processes,
+ press the button to load an image into a shared memory segment, and
+ then select an image file to load. Once the first process has loaded
+ and displayed the image, in the second process, press the button to
+ read the same image from shared memory. The second process displays
+ the same image loaded from its new loaction in shared memory.
+*/
+
+/*!
+ The class contains a data member \l {QSharedMemory} {sharedMemory},
+ which is initialized with the key "QSharedMemoryExample" to force
+ all instances of Dialog to access the same shared memory segment.
+ The constructor also connects the clicked() signal from each of the
+ three dialog buttons to the slot function appropriate for handling
+ each button.
+*/
+//! [0]
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent), sharedMemory("QSharedMemoryExample")
+{
+ ui.setupUi(this);
+ connect(ui.loadFromFileButton, SIGNAL(clicked()), SLOT(loadFromFile()));
+ connect(ui.loadFromSharedMemoryButton,
+ SIGNAL(clicked()),
+ SLOT(loadFromMemory()));
+ setWindowTitle(tr("SharedMemory Example"));
+}
+//! [0]
+
+/*!
+ This slot function is called when the \tt {Load Image From File...}
+ button is pressed on the firs Dialog process. First, it tests
+ whether the process is already connected to a shared memory segment
+ and, if so, detaches from that segment. This ensures that we always
+ start the example from the beginning if we run it multiple times
+ with the same two Dialog processes. After detaching from an existing
+ shared memory segment, the user is prompted to select an image file.
+ The selected file is loaded into a QImage. The QImage is displayed
+ in the Dialog and streamed into a QBuffer with a QDataStream.
+
+ Next, it gets a new shared memory segment from the system big enough
+ to hold the image data in the QBuffer, and it locks the segment to
+ prevent the second Dialog process from accessing it. Then it copies
+ the image from the QBuffer into the shared memory segment. Finally,
+ it unlocks the shared memory segment so the second Dialog process
+ can access it.
+
+ After this function runs, the user is expected to press the \tt
+ {Load Image from Shared Memory} button on the second Dialog process.
+
+ \sa loadFromMemory()
+ */
+//! [1]
+void Dialog::loadFromFile()
+{
+ if (sharedMemory.isAttached())
+ detach();
+
+ ui.label->setText(tr("Select an image file"));
+ QString fileName = QFileDialog::getOpenFileName(0, QString(), QString(),
+ tr("Images (*.png *.xpm *.jpg)"));
+ QImage image;
+ if (!image.load(fileName)) {
+ ui.label->setText(tr("Selected file is not an image, please select another."));
+ return;
+ }
+ ui.label->setPixmap(QPixmap::fromImage(image));
+//! [1] //! [2]
+
+ // load into shared memory
+ QBuffer buffer;
+ buffer.open(QBuffer::ReadWrite);
+ QDataStream out(&buffer);
+ out << image;
+ int size = buffer.size();
+
+ if (!sharedMemory.create(size)) {
+ ui.label->setText(tr("Unable to create shared memory segment."));
+ return;
+ }
+ sharedMemory.lock();
+ char *to = (char*)sharedMemory.data();
+ const char *from = buffer.data().data();
+ memcpy(to, from, qMin(sharedMemory.size(), size));
+ sharedMemory.unlock();
+}
+//! [2]
+
+/*!
+ This slot function is called in the second Dialog process, when the
+ user presses the \tt {Load Image from Shared Memory} button. First,
+ it attaches the process to the shared memory segment created by the
+ first Dialog process. Then it locks the segment for exclusive
+ access, copies the image data from the segment into a QBuffer, and
+ streams the QBuffer into a QImage. Then it unlocks the shared memory
+ segment, detaches from it, and finally displays the QImage in the
+ Dialog.
+
+ \sa loadFromFile()
+ */
+//! [3]
+void Dialog::loadFromMemory()
+{
+ if (!sharedMemory.attach()) {
+ ui.label->setText(tr("Unable to attach to shared memory segment.\n" \
+ "Load an image first."));
+ return;
+ }
+
+ QBuffer buffer;
+ QDataStream in(&buffer);
+ QImage image;
+
+ sharedMemory.lock();
+ buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
+ buffer.open(QBuffer::ReadOnly);
+ in >> image;
+ sharedMemory.unlock();
+
+ sharedMemory.detach();
+ ui.label->setPixmap(QPixmap::fromImage(image));
+}
+//! [3]
+
+/*!
+ This private function is called by the destructor to detach the
+ process from its shared memory segment. When the last process
+ detaches from a shared memory segment, the system releases the
+ shared memory.
+ */
+void Dialog::detach()
+{
+ if (!sharedMemory.detach())
+ ui.label->setText(tr("Unable to detach from shared memory."));
+}
+
diff --git a/examples/ipc/sharedmemory/dialog.h b/examples/ipc/sharedmemory/dialog.h
new file mode 100644
index 0000000000..ff9eacbaec
--- /dev/null
+++ b/examples/ipc/sharedmemory/dialog.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <qdialog.h>
+#include <qsharedmemory.h>
+#include "ui_dialog.h"
+
+//! [0]
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ Dialog(QWidget *parent = 0);
+
+ public slots:
+ void loadFromFile();
+ void loadFromMemory();
+
+ private:
+ void detach();
+
+ private:
+ Ui::Dialog ui;
+ QSharedMemory sharedMemory;
+};
+//! [0]
+
+#endif
+
diff --git a/examples/ipc/sharedmemory/dialog.ui b/examples/ipc/sharedmemory/dialog.ui
new file mode 100644
index 0000000000..e99d6fb3c4
--- /dev/null
+++ b/examples/ipc/sharedmemory/dialog.ui
@@ -0,0 +1,47 @@
+<ui version="4.0" >
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>451</width>
+ <height>322</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QPushButton" name="loadFromFileButton" >
+ <property name="text" >
+ <string>Load Image From File...</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Launch two of these dialogs. In the first, press the top button and load an image from a file. In the second, press the bottom button and display the loaded image from shared memory.</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QPushButton" name="loadFromSharedMemoryButton" >
+ <property name="text" >
+ <string>Display Image From Shared Memory</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/ipc/sharedmemory/image.png b/examples/ipc/sharedmemory/image.png
new file mode 100644
index 0000000000..dd93453063
--- /dev/null
+++ b/examples/ipc/sharedmemory/image.png
Binary files differ
diff --git a/examples/ipc/sharedmemory/main.cpp b/examples/ipc/sharedmemory/main.cpp
new file mode 100644
index 0000000000..279c1c0047
--- /dev/null
+++ b/examples/ipc/sharedmemory/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "dialog.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication application(argc, argv);
+ Dialog dialog;
+ dialog.show();
+ return application.exec();
+}
+//! [0]
+
diff --git a/examples/ipc/sharedmemory/qt.png b/examples/ipc/sharedmemory/qt.png
new file mode 100644
index 0000000000..60ef558efe
--- /dev/null
+++ b/examples/ipc/sharedmemory/qt.png
Binary files differ
diff --git a/examples/ipc/sharedmemory/sharedmemory.pro b/examples/ipc/sharedmemory/sharedmemory.pro
new file mode 100644
index 0000000000..8316a2c884
--- /dev/null
+++ b/examples/ipc/sharedmemory/sharedmemory.pro
@@ -0,0 +1,15 @@
+SOURCES += main.cpp \
+ dialog.cpp
+
+HEADERS += dialog.h
+
+# Forms and resources
+FORMS += dialog.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/sharedmemory
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/ipc/sharedmemory
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/README b/examples/itemviews/README
new file mode 100644
index 0000000000..0ac70f4904
--- /dev/null
+++ b/examples/itemviews/README
@@ -0,0 +1,39 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/itemviews/addressbook/adddialog.cpp b/examples/itemviews/addressbook/adddialog.cpp
new file mode 100644
index 0000000000..551e729f9b
--- /dev/null
+++ b/examples/itemviews/addressbook/adddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/addressbook/adddialog.h b/examples/itemviews/addressbook/adddialog.h
new file mode 100644
index 0000000000..d274cfba09
--- /dev/null
+++ b/examples/itemviews/addressbook/adddialog.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/addressbook/addressbook.pro b/examples/itemviews/addressbook/addressbook.pro
new file mode 100644
index 0000000000..3fbbace5c5
--- /dev/null
+++ b/examples/itemviews/addressbook/addressbook.pro
@@ -0,0 +1,22 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A646
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/itemviews/addressbook/addresswidget.cpp b/examples/itemviews/addressbook/addresswidget.cpp
new file mode 100644
index 0000000000..40b71f13fd
--- /dev/null
+++ b/examples/itemviews/addressbook/addresswidget.cpp
@@ -0,0 +1,237 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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);
+ proxyModel->setDynamicSortFilter(true);
+
+ 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/itemviews/addressbook/addresswidget.h b/examples/itemviews/addressbook/addresswidget.h
new file mode 100644
index 0000000000..9442a3da7d
--- /dev/null
+++ b/examples/itemviews/addressbook/addresswidget.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/addressbook/main.cpp b/examples/itemviews/addressbook/main.cpp
new file mode 100644
index 0000000000..455b275dfb
--- /dev/null
+++ b/examples/itemviews/addressbook/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/addressbook/mainwindow.cpp b/examples/itemviews/addressbook/mainwindow.cpp
new file mode 100644
index 0000000000..336da30d30
--- /dev/null
+++ b/examples/itemviews/addressbook/mainwindow.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+#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/itemviews/addressbook/mainwindow.h b/examples/itemviews/addressbook/mainwindow.h
new file mode 100644
index 0000000000..0134c032bd
--- /dev/null
+++ b/examples/itemviews/addressbook/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui>
+#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/itemviews/addressbook/newaddresstab.cpp b/examples/itemviews/addressbook/newaddresstab.cpp
new file mode 100644
index 0000000000..f3622604ab
--- /dev/null
+++ b/examples/itemviews/addressbook/newaddresstab.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/addressbook/newaddresstab.h b/examples/itemviews/addressbook/newaddresstab.h
new file mode 100644
index 0000000000..b849c9d62d
--- /dev/null
+++ b/examples/itemviews/addressbook/newaddresstab.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/addressbook/tablemodel.cpp b/examples/itemviews/addressbook/tablemodel.cpp
new file mode 100644
index 0000000000..19612eb809
--- /dev/null
+++ b/examples/itemviews/addressbook/tablemodel.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/addressbook/tablemodel.h b/examples/itemviews/addressbook/tablemodel.h
new file mode 100644
index 0000000000..2c30056766
--- /dev/null
+++ b/examples/itemviews/addressbook/tablemodel.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro b/examples/itemviews/basicsortfiltermodel/basicsortfiltermodel.pro
new file mode 100644
index 0000000000..0b845aff97
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/basicsortfiltermodel/main.cpp b/examples/itemviews/basicsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..84cfd05478
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/main.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/basicsortfiltermodel/window.cpp b/examples/itemviews/basicsortfiltermodel/window.cpp
new file mode 100644
index 0000000000..f35c1e18f6
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/window.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+Window::Window()
+{
+ proxyModel = new QSortFilterProxyModel;
+ proxyModel->setDynamicSortFilter(true);
+
+ sourceGroupBox = new QGroupBox(tr("Original Model"));
+ proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model"));
+
+ 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()));
+
+ 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/itemviews/basicsortfiltermodel/window.h b/examples/itemviews/basicsortfiltermodel/window.h
new file mode 100644
index 0000000000..92b5008384
--- /dev/null
+++ b/examples/itemviews/basicsortfiltermodel/window.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/chart/chart.pro b/examples/itemviews/chart/chart.pro
new file mode 100644
index 0000000000..250e1e120c
--- /dev/null
+++ b/examples/itemviews/chart/chart.pro
@@ -0,0 +1,20 @@
+HEADERS = mainwindow.h \
+ pieview.h
+RESOURCES = chart.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ pieview.cpp
+unix:!mac:!symbian:!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
+
+symbian {
+ TARGET.UID3 = 0xA000A647
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/itemviews/chart/chart.qrc b/examples/itemviews/chart/chart.qrc
new file mode 100644
index 0000000000..7401d4d2f8
--- /dev/null
+++ b/examples/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/itemviews/chart/main.cpp b/examples/itemviews/chart/main.cpp
new file mode 100644
index 0000000000..936654097f
--- /dev/null
+++ b/examples/itemviews/chart/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/chart/mainwindow.cpp b/examples/itemviews/chart/mainwindow.cpp
new file mode 100644
index 0000000000..df6f01abc2
--- /dev/null
+++ b/examples/itemviews/chart/mainwindow.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/chart/mainwindow.h b/examples/itemviews/chart/mainwindow.h
new file mode 100644
index 0000000000..4d45f1e4be
--- /dev/null
+++ b/examples/itemviews/chart/mainwindow.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/chart/mydata.cht b/examples/itemviews/chart/mydata.cht
new file mode 100644
index 0000000000..029fd81458
--- /dev/null
+++ b/examples/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/itemviews/chart/pieview.cpp b/examples/itemviews/chart/pieview.cpp
new file mode 100644
index 0000000000..75c47ac5e9
--- /dev/null
+++ b/examples/itemviews/chart/pieview.cpp
@@ -0,0 +1,561 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <math.h>
+#include <QtGui>
+
+#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)
+{
+ 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();
+ QStyle::State state = option.state;
+
+ QBrush background = option.palette.base();
+ QPen foreground(option.palette.color(QPalette::WindowText));
+ QPen textPen(option.palette.color(QPalette::Text));
+ QPen highlightedPen(option.palette.color(QPalette::HighlightedText));
+
+ QPainter painter(viewport());
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ painter.fillRect(event->rect(), background);
+ painter.setPen(foreground);
+
+ // Viewport rectangles
+ QRect pieRect = QRect(margin, margin, pieSize, pieSize);
+ QPoint keyPoint = QPoint(totalSize - horizontalScrollBar()->value(),
+ margin - verticalScrollBar()->value());
+
+ 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.intersect(contentsRect).isEmpty())
+ 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/itemviews/chart/pieview.h b/examples/itemviews/chart/pieview.h
new file mode 100644
index 0000000000..7afb3e51e6
--- /dev/null
+++ b/examples/itemviews/chart/pieview.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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);
+ 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/itemviews/chart/qtdata.cht b/examples/itemviews/chart/qtdata.cht
new file mode 100644
index 0000000000..6386246c4b
--- /dev/null
+++ b/examples/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/itemviews/coloreditorfactory/coloreditorfactory.pro b/examples/itemviews/coloreditorfactory/coloreditorfactory.pro
new file mode 100644
index 0000000000..a8187b139d
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/coloreditorfactory.pro
@@ -0,0 +1,13 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/coloreditorfactory/colorlisteditor.cpp b/examples/itemviews/coloreditorfactory/colorlisteditor.cpp
new file mode 100644
index 0000000000..d8ce45b5ab
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/colorlisteditor.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/coloreditorfactory/colorlisteditor.h b/examples/itemviews/coloreditorfactory/colorlisteditor.h
new file mode 100644
index 0000000000..2fdc23bb5e
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/colorlisteditor.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/coloreditorfactory/main.cpp b/examples/itemviews/coloreditorfactory/main.cpp
new file mode 100644
index 0000000000..aa46cc5c53
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/itemviews/coloreditorfactory/window.cpp b/examples/itemviews/coloreditorfactory/window.cpp
new file mode 100644
index 0000000000..f234af1367
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/window.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/coloreditorfactory/window.h b/examples/itemviews/coloreditorfactory/window.h
new file mode 100644
index 0000000000..5aad0c21b9
--- /dev/null
+++ b/examples/itemviews/coloreditorfactory/window.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ void createGUI();
+};
+
+#endif
diff --git a/examples/itemviews/combowidgetmapper/combowidgetmapper.pro b/examples/itemviews/combowidgetmapper/combowidgetmapper.pro
new file mode 100644
index 0000000000..5a0d562003
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/combowidgetmapper.pro
@@ -0,0 +1,9 @@
+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
diff --git a/examples/itemviews/combowidgetmapper/main.cpp b/examples/itemviews/combowidgetmapper/main.cpp
new file mode 100644
index 0000000000..41e756d8ad
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/combowidgetmapper/window.cpp b/examples/itemviews/combowidgetmapper/window.cpp
new file mode 100644
index 0000000000..667fc4b8d2
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/window.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/combowidgetmapper/window.h b/examples/itemviews/combowidgetmapper/window.h
new file mode 100644
index 0000000000..e890ce0eda
--- /dev/null
+++ b/examples/itemviews/combowidgetmapper/window.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/customsortfiltermodel/customsortfiltermodel.pro b/examples/itemviews/customsortfiltermodel/customsortfiltermodel.pro
new file mode 100644
index 0000000000..193dfd9da3
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/customsortfiltermodel/main.cpp b/examples/itemviews/customsortfiltermodel/main.cpp
new file mode 100644
index 0000000000..b35b847663
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/main.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
new file mode 100644
index 0000000000..7e91444997
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/customsortfiltermodel/mysortfilterproxymodel.h b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
new file mode 100644
index 0000000000..7ab7d590c2
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/mysortfilterproxymodel.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/customsortfiltermodel/window.cpp b/examples/itemviews/customsortfiltermodel/window.cpp
new file mode 100644
index 0000000000..555e854044
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/window.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mysortfilterproxymodel.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ proxyModel = new MySortFilterProxyModel(this);
+ proxyModel->setDynamicSortFilter(true);
+//! [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/itemviews/customsortfiltermodel/window.h b/examples/itemviews/customsortfiltermodel/window.h
new file mode 100644
index 0000000000..15baffc2c6
--- /dev/null
+++ b/examples/itemviews/customsortfiltermodel/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/dirview/dirview.pro b/examples/itemviews/dirview/dirview.pro
new file mode 100644
index 0000000000..fc87b4cfe6
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/dirview/main.cpp b/examples/itemviews/dirview/main.cpp
new file mode 100644
index 0000000000..ffa287b321
--- /dev/null
+++ b/examples/itemviews/dirview/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+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/itemviews/editabletreemodel/default.txt b/examples/itemviews/editabletreemodel/default.txt
new file mode 100644
index 0000000000..2b2fb579ae
--- /dev/null
+++ b/examples/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/itemviews/editabletreemodel/editabletreemodel.pro b/examples/itemviews/editabletreemodel/editabletreemodel.pro
new file mode 100644
index 0000000000..1137f5cfa5
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/editabletreemodel/editabletreemodel.qrc b/examples/itemviews/editabletreemodel/editabletreemodel.qrc
new file mode 100644
index 0000000000..2fb48f2e62
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/editabletreemodel.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>default.txt</file>
+ </qresource>
+</RCC>
diff --git a/examples/itemviews/editabletreemodel/main.cpp b/examples/itemviews/editabletreemodel/main.cpp
new file mode 100644
index 0000000000..b6e6b0277d
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/editabletreemodel/mainwindow.cpp b/examples/itemviews/editabletreemodel/mainwindow.cpp
new file mode 100644
index 0000000000..6f08ced0e9
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/mainwindow.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/editabletreemodel/mainwindow.h b/examples/itemviews/editabletreemodel/mainwindow.h
new file mode 100644
index 0000000000..3dc8291d26
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/mainwindow.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/editabletreemodel/mainwindow.ui b/examples/itemviews/editabletreemodel/mainwindow.ui
new file mode 100644
index 0000000000..2ad084ae24
--- /dev/null
+++ b/examples/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/itemviews/editabletreemodel/treeitem.cpp b/examples/itemviews/editabletreemodel/treeitem.cpp
new file mode 100644
index 0000000000..00446aa89b
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treeitem.cpp
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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/itemviews/editabletreemodel/treeitem.h b/examples/itemviews/editabletreemodel/treeitem.h
new file mode 100644
index 0000000000..7a54ce4f26
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treeitem.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/editabletreemodel/treemodel.cpp b/examples/itemviews/editabletreemodel/treemodel.cpp
new file mode 100644
index 0000000000..8b44438623
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treemodel.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/editabletreemodel/treemodel.h b/examples/itemviews/editabletreemodel/treemodel.h
new file mode 100644
index 0000000000..549a437012
--- /dev/null
+++ b/examples/itemviews/editabletreemodel/treemodel.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/fetchmore/fetchmore.pro b/examples/itemviews/fetchmore/fetchmore.pro
new file mode 100644
index 0000000000..2951d93faf
--- /dev/null
+++ b/examples/itemviews/fetchmore/fetchmore.pro
@@ -0,0 +1,12 @@
+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
+
diff --git a/examples/itemviews/fetchmore/filelistmodel.cpp b/examples/itemviews/fetchmore/filelistmodel.cpp
new file mode 100644
index 0000000000..727c658a3d
--- /dev/null
+++ b/examples/itemviews/fetchmore/filelistmodel.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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);
+
+ fileList = dir.entryList();
+ fileCount = 0;
+ reset();
+}
+//![0]
+
diff --git a/examples/itemviews/fetchmore/filelistmodel.h b/examples/itemviews/fetchmore/filelistmodel.h
new file mode 100644
index 0000000000..9f0898eb8e
--- /dev/null
+++ b/examples/itemviews/fetchmore/filelistmodel.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/fetchmore/main.cpp b/examples/itemviews/fetchmore/main.cpp
new file mode 100644
index 0000000000..aedfd9f8d3
--- /dev/null
+++ b/examples/itemviews/fetchmore/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/fetchmore/window.cpp b/examples/itemviews/fetchmore/window.cpp
new file mode 100644
index 0000000000..29dbf12b21
--- /dev/null
+++ b/examples/itemviews/fetchmore/window.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/fetchmore/window.h b/examples/itemviews/fetchmore/window.h
new file mode 100644
index 0000000000..f726caedcf
--- /dev/null
+++ b/examples/itemviews/fetchmore/window.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/frozencolumn/freezetablewidget.cpp b/examples/itemviews/frozencolumn/freezetablewidget.cpp
new file mode 100644
index 0000000000..357d387321
--- /dev/null
+++ b/examples/itemviews/frozencolumn/freezetablewidget.cpp
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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()->setResizeMode(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/itemviews/frozencolumn/freezetablewidget.h b/examples/itemviews/frozencolumn/freezetablewidget.h
new file mode 100644
index 0000000000..8ba8d17aa7
--- /dev/null
+++ b/examples/itemviews/frozencolumn/freezetablewidget.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/frozencolumn/frozencolumn.pro b/examples/itemviews/frozencolumn/frozencolumn.pro
new file mode 100644
index 0000000000..a055fd93c0
--- /dev/null
+++ b/examples/itemviews/frozencolumn/frozencolumn.pro
@@ -0,0 +1,9 @@
+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
diff --git a/examples/itemviews/frozencolumn/grades.qrc b/examples/itemviews/frozencolumn/grades.qrc
new file mode 100644
index 0000000000..5f16d56931
--- /dev/null
+++ b/examples/itemviews/frozencolumn/grades.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>grades.txt</file>
+ </qresource>
+</RCC>
diff --git a/examples/itemviews/frozencolumn/grades.txt b/examples/itemviews/frozencolumn/grades.txt
new file mode 100644
index 0000000000..e1c6fcc49e
--- /dev/null
+++ b/examples/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/itemviews/frozencolumn/main.cpp b/examples/itemviews/frozencolumn/main.cpp
new file mode 100644
index 0000000000..f6aa489d05
--- /dev/null
+++ b/examples/itemviews/frozencolumn/main.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/itemviews.pro b/examples/itemviews/itemviews.pro
new file mode 100644
index 0000000000..adc313b864
--- /dev/null
+++ b/examples/itemviews/itemviews.pro
@@ -0,0 +1,29 @@
+TEMPLATE = subdirs
+SUBDIRS = addressbook \
+ basicsortfiltermodel \
+ chart \
+ coloreditorfactory \
+ combowidgetmapper \
+ customsortfiltermodel \
+ dirview \
+ editabletreemodel \
+ fetchmore \
+ frozencolumn \
+ pixelator \
+ puzzle \
+ simpledommodel \
+ simpletreemodel \
+ simplewidgetmapper \
+ spinboxdelegate \
+ stardelegate
+
+symbian: SUBDIRS = \
+ addressbook \
+ chart
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/itemviews
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/pixelator/imagemodel.cpp b/examples/itemviews/pixelator/imagemodel.cpp
new file mode 100644
index 0000000000..abf92ddef5
--- /dev/null
+++ b/examples/itemviews/pixelator/imagemodel.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "imagemodel.h"
+
+//! [0]
+ImageModel::ImageModel(QObject *parent)
+ : QAbstractTableModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+void ImageModel::setImage(const QImage &image)
+{
+ modelImage = image;
+ reset();
+}
+//! [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/itemviews/pixelator/imagemodel.h b/examples/itemviews/pixelator/imagemodel.h
new file mode 100644
index 0000000000..158f31dc0b
--- /dev/null
+++ b/examples/itemviews/pixelator/imagemodel.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/pixelator/images.qrc b/examples/itemviews/pixelator/images.qrc
new file mode 100644
index 0000000000..c105e13895
--- /dev/null
+++ b/examples/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/itemviews/pixelator/images/qt.png b/examples/itemviews/pixelator/images/qt.png
new file mode 100644
index 0000000000..a2c9c77c16
--- /dev/null
+++ b/examples/itemviews/pixelator/images/qt.png
Binary files differ
diff --git a/examples/itemviews/pixelator/main.cpp b/examples/itemviews/pixelator/main.cpp
new file mode 100644
index 0000000000..e7f45e3f42
--- /dev/null
+++ b/examples/itemviews/pixelator/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/pixelator/mainwindow.cpp b/examples/itemviews/pixelator/mainwindow.cpp
new file mode 100644
index 0000000000..62c6830313
--- /dev/null
+++ b/examples/itemviews/pixelator/mainwindow.cpp
@@ -0,0 +1,244 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/pixelator/mainwindow.h b/examples/itemviews/pixelator/mainwindow.h
new file mode 100644
index 0000000000..5dc2a908db
--- /dev/null
+++ b/examples/itemviews/pixelator/mainwindow.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/pixelator/pixelator.pro b/examples/itemviews/pixelator/pixelator.pro
new file mode 100644
index 0000000000..fecffcc64b
--- /dev/null
+++ b/examples/itemviews/pixelator/pixelator.pro
@@ -0,0 +1,16 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/pixelator/pixeldelegate.cpp b/examples/itemviews/pixelator/pixeldelegate.cpp
new file mode 100644
index 0000000000..9ec88e614c
--- /dev/null
+++ b/examples/itemviews/pixelator/pixeldelegate.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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(QBrush(Qt::black));
+//! [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/itemviews/pixelator/pixeldelegate.h b/examples/itemviews/pixelator/pixeldelegate.h
new file mode 100644
index 0000000000..3ff73b53e5
--- /dev/null
+++ b/examples/itemviews/pixelator/pixeldelegate.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/puzzle/example.jpg b/examples/itemviews/puzzle/example.jpg
new file mode 100644
index 0000000000..e09fb70757
--- /dev/null
+++ b/examples/itemviews/puzzle/example.jpg
Binary files differ
diff --git a/examples/itemviews/puzzle/main.cpp b/examples/itemviews/puzzle/main.cpp
new file mode 100644
index 0000000000..60341948ab
--- /dev/null
+++ b/examples/itemviews/puzzle/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/puzzle/mainwindow.cpp b/examples/itemviews/puzzle/mainwindow.cpp
new file mode 100644
index 0000000000..4d6da116bf
--- /dev/null
+++ b/examples/itemviews/puzzle/mainwindow.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <stdlib.h>
+
+#include "mainwindow.h"
+#include "piecesmodel.h"
+#include "puzzlewidget.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupMenus();
+ setupWidgets();
+ model = new PiecesModel(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(400,
+ 400, 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);
+
+ piecesList = new QListView;
+ piecesList->setDragEnabled(true);
+ piecesList->setViewMode(QListView::IconMode);
+ piecesList->setIconSize(QSize(60, 60));
+ piecesList->setGridSize(QSize(80, 80));
+ piecesList->setSpacing(10);
+ piecesList->setMovement(QListView::Snap);
+ piecesList->setAcceptDrops(true);
+ piecesList->setDropIndicatorShown(true);
+
+ PiecesModel *model = new PiecesModel(this);
+ piecesList->setModel(model);
+
+ puzzleWidget = new PuzzleWidget;
+
+ connect(puzzleWidget, SIGNAL(puzzleCompleted()),
+ this, SLOT(setCompleted()), Qt::QueuedConnection);
+
+ frameLayout->addWidget(piecesList);
+ frameLayout->addWidget(puzzleWidget);
+ setCentralWidget(frame);
+}
diff --git a/examples/itemviews/puzzle/mainwindow.h b/examples/itemviews/puzzle/mainwindow.h
new file mode 100644
index 0000000000..e242adb173
--- /dev/null
+++ b/examples/itemviews/puzzle/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/puzzle/piecesmodel.cpp b/examples/itemviews/puzzle/piecesmodel.cpp
new file mode 100644
index 0000000000..4235050d9d
--- /dev/null
+++ b/examples/itemviews/puzzle/piecesmodel.cpp
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "piecesmodel.h"
+
+PiecesModel::PiecesModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+}
+
+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(60, 60,
+ 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*80, y*80, 80, 80);
+ addPiece(pieceImage, QPoint(x, y));
+ }
+ }
+}
diff --git a/examples/itemviews/puzzle/piecesmodel.h b/examples/itemviews/puzzle/piecesmodel.h
new file mode 100644
index 0000000000..30bbdf83b2
--- /dev/null
+++ b/examples/itemviews/puzzle/piecesmodel.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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(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;
+};
+
+#endif
diff --git a/examples/itemviews/puzzle/puzzle.pro b/examples/itemviews/puzzle/puzzle.pro
new file mode 100644
index 0000000000..3939397b7c
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzle.pro
@@ -0,0 +1,21 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince* {
+ DEPLOYMENT_PLUGIN += qjpeg qgif qtiff
+}
+
diff --git a/examples/itemviews/puzzle/puzzle.qrc b/examples/itemviews/puzzle/puzzle.qrc
new file mode 100644
index 0000000000..4076cec026
--- /dev/null
+++ b/examples/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/itemviews/puzzle/puzzlewidget.cpp b/examples/itemviews/puzzle/puzzlewidget.cpp
new file mode 100644
index 0000000000..a0d769d20a
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzlewidget.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "puzzlewidget.h"
+
+PuzzleWidget::PuzzleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setAcceptDrops(true);
+ setMinimumSize(400, 400);
+ setMaximumSize(400, 400);
+}
+
+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.unite(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()/80, square.y()/80)) {
+ 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()/80, square.y()/80))
+ 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()/80, square.y()/80))
+ 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()/80 * 80, position.y()/80 * 80, 80, 80);
+}
diff --git a/examples/itemviews/puzzle/puzzlewidget.h b/examples/itemviews/puzzle/puzzlewidget.h
new file mode 100644
index 0000000000..e0356b48fd
--- /dev/null
+++ b/examples/itemviews/puzzle/puzzlewidget.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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(QWidget *parent = 0);
+ void clear();
+
+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;
+};
+
+#endif
diff --git a/examples/itemviews/simpledommodel/domitem.cpp b/examples/itemviews/simpledommodel/domitem.cpp
new file mode 100644
index 0000000000..ed266c71a1
--- /dev/null
+++ b/examples/itemviews/simpledommodel/domitem.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpledommodel/domitem.h b/examples/itemviews/simpledommodel/domitem.h
new file mode 100644
index 0000000000..0348218d32
--- /dev/null
+++ b/examples/itemviews/simpledommodel/domitem.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpledommodel/dommodel.cpp b/examples/itemviews/simpledommodel/dommodel.cpp
new file mode 100644
index 0000000000..7a5e9ca5c0
--- /dev/null
+++ b/examples/itemviews/simpledommodel/dommodel.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/simpledommodel/dommodel.h b/examples/itemviews/simpledommodel/dommodel.h
new file mode 100644
index 0000000000..0b91a115a6
--- /dev/null
+++ b/examples/itemviews/simpledommodel/dommodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpledommodel/main.cpp b/examples/itemviews/simpledommodel/main.cpp
new file mode 100644
index 0000000000..74a14b0f8c
--- /dev/null
+++ b/examples/itemviews/simpledommodel/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpledommodel/mainwindow.cpp b/examples/itemviews/simpledommodel/mainwindow.cpp
new file mode 100644
index 0000000000..9803726d9f
--- /dev/null
+++ b/examples/itemviews/simpledommodel/mainwindow.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDomDocument>
+#include <QFile>
+#include <QtGui>
+
+#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/itemviews/simpledommodel/mainwindow.h b/examples/itemviews/simpledommodel/mainwindow.h
new file mode 100644
index 0000000000..6a0e6e5239
--- /dev/null
+++ b/examples/itemviews/simpledommodel/mainwindow.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpledommodel/simpledommodel.pro b/examples/itemviews/simpledommodel/simpledommodel.pro
new file mode 100644
index 0000000000..87d673f3a1
--- /dev/null
+++ b/examples/itemviews/simpledommodel/simpledommodel.pro
@@ -0,0 +1,17 @@
+HEADERS = domitem.h \
+ dommodel.h \
+ mainwindow.h
+SOURCES = domitem.cpp \
+ dommodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+CONFIG += qt
+QT += xml
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/simpletreemodel/default.txt b/examples/itemviews/simpletreemodel/default.txt
new file mode 100644
index 0000000000..2b2fb579ae
--- /dev/null
+++ b/examples/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/itemviews/simpletreemodel/main.cpp b/examples/itemviews/simpletreemodel/main.cpp
new file mode 100644
index 0000000000..b14b52498b
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/simpletreemodel/simpletreemodel.pro b/examples/itemviews/simpletreemodel/simpletreemodel.pro
new file mode 100644
index 0000000000..8b1f78e54f
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/simpletreemodel/simpletreemodel.qrc b/examples/itemviews/simpletreemodel/simpletreemodel.qrc
new file mode 100644
index 0000000000..a8ecc98d28
--- /dev/null
+++ b/examples/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/itemviews/simpletreemodel/treeitem.cpp b/examples/itemviews/simpletreemodel/treeitem.cpp
new file mode 100644
index 0000000000..ac310e8226
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treeitem.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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/itemviews/simpletreemodel/treeitem.h b/examples/itemviews/simpletreemodel/treeitem.h
new file mode 100644
index 0000000000..a220a7d8bc
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treeitem.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simpletreemodel/treemodel.cpp b/examples/itemviews/simpletreemodel/treemodel.cpp
new file mode 100644
index 0000000000..3041d3b1ef
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treemodel.cpp
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ treemodel.cpp
+
+ Provides a simple tree model to show how to create and use hierarchical
+ models.
+*/
+
+#include <QtGui>
+
+#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/itemviews/simpletreemodel/treemodel.h b/examples/itemviews/simpletreemodel/treemodel.h
new file mode 100644
index 0000000000..6d1adb6b17
--- /dev/null
+++ b/examples/itemviews/simpletreemodel/treemodel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simplewidgetmapper/main.cpp b/examples/itemviews/simplewidgetmapper/main.cpp
new file mode 100644
index 0000000000..41e756d8ad
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/simplewidgetmapper/simplewidgetmapper.pro b/examples/itemviews/simplewidgetmapper/simplewidgetmapper.pro
new file mode 100644
index 0000000000..bdb0219537
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/simplewidgetmapper/window.cpp b/examples/itemviews/simplewidgetmapper/window.cpp
new file mode 100644
index 0000000000..a6ed1bc984
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/window.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/simplewidgetmapper/window.h b/examples/itemviews/simplewidgetmapper/window.h
new file mode 100644
index 0000000000..57d191e144
--- /dev/null
+++ b/examples/itemviews/simplewidgetmapper/window.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/spinboxdelegate/delegate.cpp b/examples/itemviews/spinboxdelegate/delegate.cpp
new file mode 100644
index 0000000000..7837cbf670
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/delegate.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ delegate.cpp
+
+ A delegate that allows the user to change integer values from the model
+ using a spin box widget.
+*/
+
+#include <QtGui>
+
+#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/itemviews/spinboxdelegate/delegate.h b/examples/itemviews/spinboxdelegate/delegate.h
new file mode 100644
index 0000000000..c7b2e7f156
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/delegate.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/spinboxdelegate/main.cpp b/examples/itemviews/spinboxdelegate/main.cpp
new file mode 100644
index 0000000000..e078d7f2df
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/main.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ 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/itemviews/spinboxdelegate/spinboxdelegate.pro b/examples/itemviews/spinboxdelegate/spinboxdelegate.pro
new file mode 100644
index 0000000000..c7162eb69c
--- /dev/null
+++ b/examples/itemviews/spinboxdelegate/spinboxdelegate.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/itemviews/stardelegate/main.cpp b/examples/itemviews/stardelegate/main.cpp
new file mode 100644
index 0000000000..1af54d0d84
--- /dev/null
+++ b/examples/itemviews/stardelegate/main.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/stardelegate/stardelegate.cpp b/examples/itemviews/stardelegate/stardelegate.cpp
new file mode 100644
index 0000000000..c784da2ffd
--- /dev/null
+++ b/examples/itemviews/stardelegate/stardelegate.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/stardelegate/stardelegate.h b/examples/itemviews/stardelegate/stardelegate.h
new file mode 100644
index 0000000000..0e2a946c28
--- /dev/null
+++ b/examples/itemviews/stardelegate/stardelegate.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/stardelegate/stardelegate.pro b/examples/itemviews/stardelegate/stardelegate.pro
new file mode 100644
index 0000000000..078ef143c3
--- /dev/null
+++ b/examples/itemviews/stardelegate/stardelegate.pro
@@ -0,0 +1,16 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/itemviews/stardelegate/stareditor.cpp b/examples/itemviews/stardelegate/stareditor.cpp
new file mode 100644
index 0000000000..453c75dbb7
--- /dev/null
+++ b/examples/itemviews/stardelegate/stareditor.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/itemviews/stardelegate/stareditor.h b/examples/itemviews/stardelegate/stareditor.h
new file mode 100644
index 0000000000..9dfc503124
--- /dev/null
+++ b/examples/itemviews/stardelegate/stareditor.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/itemviews/stardelegate/starrating.cpp b/examples/itemviews/stardelegate/starrating.cpp
new file mode 100644
index 0000000000..121d4a2ca1
--- /dev/null
+++ b/examples/itemviews/stardelegate/starrating.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#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/itemviews/stardelegate/starrating.h b/examples/itemviews/stardelegate/starrating.h
new file mode 100644
index 0000000000..68b747b94c
--- /dev/null
+++ b/examples/itemviews/stardelegate/starrating.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/ja_JP/linguist/hellotr/hellotr.pro b/examples/ja_JP/linguist/hellotr/hellotr.pro
new file mode 100644
index 0000000000..3aa6bdd15f
--- /dev/null
+++ b/examples/ja_JP/linguist/hellotr/hellotr.pro
@@ -0,0 +1,13 @@
+#! [0]
+SOURCES = main.cpp
+#! [0] #! [1]
+TRANSLATIONS = hellotr_ja.ts
+#! [1]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/hellotr
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/hellotr
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/ja_JP/linguist/hellotr/main.cpp b/examples/ja_JP/linguist/hellotr/main.cpp
new file mode 100644
index 0000000000..517cb7b202
--- /dev/null
+++ b/examples/ja_JP/linguist/hellotr/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QPushButton>
+//! [0]
+#include <QTranslator>
+//! [0]
+
+//! [1] //! [2]
+int main(int argc, char *argv[])
+//! [1] //! [3] //! [4]
+{
+ QApplication app(argc, argv);
+//! [3]
+
+//! [5]
+ QTranslator translator;
+//! [5] //! [6]
+ translator.load("hellotr_ja");
+//! [6] //! [7]
+ app.installTranslator(&translator);
+//! [4] //! [7]
+
+//! [8]
+ QPushButton hello(QPushButton::tr("Hello world!"));
+//! [8]
+ hello.resize(100, 30);
+
+ hello.show();
+ return app.exec();
+}
+//! [2]
diff --git a/examples/layouts/README b/examples/layouts/README
new file mode 100644
index 0000000000..edaea78463
--- /dev/null
+++ b/examples/layouts/README
@@ -0,0 +1,41 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/layouts/basiclayouts/basiclayouts.pro b/examples/layouts/basiclayouts/basiclayouts.pro
new file mode 100644
index 0000000000..4b0a657cc1
--- /dev/null
+++ b/examples/layouts/basiclayouts/basiclayouts.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/layouts/basiclayouts/dialog.cpp b/examples/layouts/basiclayouts/dialog.cpp
new file mode 100644
index 0000000000..e3cbc08948
--- /dev/null
+++ b/examples/layouts/basiclayouts/dialog.cpp
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/layouts/basiclayouts/dialog.h b/examples/layouts/basiclayouts/dialog.h
new file mode 100644
index 0000000000..340740630b
--- /dev/null
+++ b/examples/layouts/basiclayouts/dialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/basiclayouts/main.cpp b/examples/layouts/basiclayouts/main.cpp
new file mode 100644
index 0000000000..8aa11f488d
--- /dev/null
+++ b/examples/layouts/basiclayouts/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ return dialog.exec();
+}
diff --git a/examples/layouts/borderlayout/borderlayout.cpp b/examples/layouts/borderlayout/borderlayout.cpp
new file mode 100644
index 0000000000..e6c2bbc79e
--- /dev/null
+++ b/examples/layouts/borderlayout/borderlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/layouts/borderlayout/borderlayout.h b/examples/layouts/borderlayout/borderlayout.h
new file mode 100644
index 0000000000..d59c33a38b
--- /dev/null
+++ b/examples/layouts/borderlayout/borderlayout.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/borderlayout/borderlayout.pro b/examples/layouts/borderlayout/borderlayout.pro
new file mode 100644
index 0000000000..372029aaf9
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/layouts/borderlayout/main.cpp b/examples/layouts/borderlayout/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/layouts/borderlayout/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/borderlayout/window.cpp b/examples/layouts/borderlayout/window.cpp
new file mode 100644
index 0000000000..da32600114
--- /dev/null
+++ b/examples/layouts/borderlayout/window.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/layouts/borderlayout/window.h b/examples/layouts/borderlayout/window.h
new file mode 100644
index 0000000000..598bc0a3f7
--- /dev/null
+++ b/examples/layouts/borderlayout/window.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/dynamiclayouts/dialog.cpp b/examples/layouts/dynamiclayouts/dialog.cpp
new file mode 100644
index 0000000000..58711bee7f
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/dialog.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/layouts/dynamiclayouts/dialog.h b/examples/layouts/dynamiclayouts/dialog.h
new file mode 100644
index 0000000000..9409be1b57
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/dialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#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/layouts/dynamiclayouts/dynamiclayouts.pro b/examples/layouts/dynamiclayouts/dynamiclayouts.pro
new file mode 100644
index 0000000000..5a4133c76c
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/dynamiclayouts.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/layouts/dynamiclayouts/main.cpp b/examples/layouts/dynamiclayouts/main.cpp
new file mode 100644
index 0000000000..8aa11f488d
--- /dev/null
+++ b/examples/layouts/dynamiclayouts/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ return dialog.exec();
+}
diff --git a/examples/layouts/flowlayout/flowlayout.cpp b/examples/layouts/flowlayout/flowlayout.cpp
new file mode 100644
index 0000000000..b570af8e78
--- /dev/null
+++ b/examples/layouts/flowlayout/flowlayout.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/layouts/flowlayout/flowlayout.h b/examples/layouts/flowlayout/flowlayout.h
new file mode 100644
index 0000000000..b54fc67b71
--- /dev/null
+++ b/examples/layouts/flowlayout/flowlayout.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/flowlayout/flowlayout.pro b/examples/layouts/flowlayout/flowlayout.pro
new file mode 100644
index 0000000000..609f9881e5
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/layouts/flowlayout/main.cpp b/examples/layouts/flowlayout/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/layouts/flowlayout/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/flowlayout/window.cpp b/examples/layouts/flowlayout/window.cpp
new file mode 100644
index 0000000000..51f09a8b83
--- /dev/null
+++ b/examples/layouts/flowlayout/window.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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] \ No newline at end of file
diff --git a/examples/layouts/flowlayout/window.h b/examples/layouts/flowlayout/window.h
new file mode 100644
index 0000000000..4b57f47be3
--- /dev/null
+++ b/examples/layouts/flowlayout/window.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/layouts/layouts.pro b/examples/layouts/layouts.pro
new file mode 100644
index 0000000000..57d85b4b35
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/linguist/README b/examples/linguist/README
new file mode 100644
index 0000000000..d1ef0057e4
--- /dev/null
+++ b/examples/linguist/README
@@ -0,0 +1,37 @@
+Internationalization is a core feature of Qt. These examples show how to
+access translation and localization facilities at run-time.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/linguist/arrowpad/arrowpad.cpp b/examples/linguist/arrowpad/arrowpad.cpp
new file mode 100644
index 0000000000..1a5357a3ca
--- /dev/null
+++ b/examples/linguist/arrowpad/arrowpad.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "arrowpad.h"
+
+ArrowPad::ArrowPad(QWidget *parent)
+ : QWidget(parent)
+{
+//! [0]
+ upButton = new QPushButton(tr("&Up"));
+//! [0] //! [1]
+ downButton = new QPushButton(tr("&Down"));
+//! [1] //! [2]
+ leftButton = new QPushButton(tr("&Left"));
+//! [2] //! [3]
+ rightButton = new QPushButton(tr("&Right"));
+//! [3]
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(upButton, 0, 1);
+ mainLayout->addWidget(leftButton, 1, 0);
+ mainLayout->addWidget(rightButton, 1, 2);
+ mainLayout->addWidget(downButton, 2, 1);
+ setLayout(mainLayout);
+}
diff --git a/examples/linguist/arrowpad/arrowpad.h b/examples/linguist/arrowpad/arrowpad.h
new file mode 100644
index 0000000000..f0c77dbf70
--- /dev/null
+++ b/examples/linguist/arrowpad/arrowpad.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ARROWPAD_H
+#define ARROWPAD_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+QT_END_NAMESPACE
+
+//! [0]
+class ArrowPad : public QWidget
+//! [0] //! [1]
+{
+//! [1] //! [2]
+ Q_OBJECT
+//! [2]
+
+public:
+ ArrowPad(QWidget *parent = 0);
+
+private:
+ QPushButton *upButton;
+ QPushButton *downButton;
+ QPushButton *leftButton;
+ QPushButton *rightButton;
+};
+
+#endif
diff --git a/examples/linguist/arrowpad/arrowpad.pro b/examples/linguist/arrowpad/arrowpad.pro
new file mode 100644
index 0000000000..2f8c5f5786
--- /dev/null
+++ b/examples/linguist/arrowpad/arrowpad.pro
@@ -0,0 +1,18 @@
+#! [0]
+HEADERS = arrowpad.h \
+ mainwindow.h
+SOURCES = arrowpad.cpp \
+ main.cpp \
+ mainwindow.cpp
+#! [0] #! [1]
+TRANSLATIONS = arrowpad_fr.ts \
+ arrowpad_nl.ts
+#! [1]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/arrowpad
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/arrowpad
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/linguist/arrowpad/main.cpp b/examples/linguist/arrowpad/main.cpp
new file mode 100644
index 0000000000..dc8cae8251
--- /dev/null
+++ b/examples/linguist/arrowpad/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+//! [0] //! [1]
+{
+ QApplication app(argc, argv);
+
+ QString locale = QLocale::system().name();
+
+//! [2]
+ QTranslator translator;
+//! [2] //! [3]
+ translator.load(QString("arrowpad_") + locale);
+ app.installTranslator(&translator);
+//! [1] //! [3]
+
+ MainWindow mainWindow;
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/linguist/arrowpad/mainwindow.cpp b/examples/linguist/arrowpad/mainwindow.cpp
new file mode 100644
index 0000000000..8c3ccf2fd3
--- /dev/null
+++ b/examples/linguist/arrowpad/mainwindow.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "arrowpad.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+//! [0]
+ arrowPad = new ArrowPad;
+//! [0]
+ setCentralWidget(arrowPad);
+
+//! [1]
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+//! [1]
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(exitAct);
+}
diff --git a/examples/linguist/arrowpad/mainwindow.h b/examples/linguist/arrowpad/mainwindow.h
new file mode 100644
index 0000000000..3908c335b9
--- /dev/null
+++ b/examples/linguist/arrowpad/mainwindow.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+QT_END_NAMESPACE
+class ArrowPad;
+
+//! [0]
+class MainWindow : public QMainWindow
+//! [0] //! [1]
+{
+ Q_OBJECT
+//! [1]
+
+public:
+ MainWindow();
+
+private:
+ ArrowPad *arrowPad;
+ QMenu *fileMenu;
+ QAction *exitAct;
+};
+
+#endif
diff --git a/examples/linguist/hellotr/hellotr.pro b/examples/linguist/hellotr/hellotr.pro
new file mode 100644
index 0000000000..6995f11b2a
--- /dev/null
+++ b/examples/linguist/hellotr/hellotr.pro
@@ -0,0 +1,13 @@
+#! [0]
+SOURCES = main.cpp
+#! [0] #! [1]
+TRANSLATIONS = hellotr_la.ts
+#! [1]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/hellotr
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/hellotr
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/linguist/hellotr/main.cpp b/examples/linguist/hellotr/main.cpp
new file mode 100644
index 0000000000..5d3e4d75a4
--- /dev/null
+++ b/examples/linguist/hellotr/main.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QPushButton>
+//! [0]
+#include <QTranslator>
+//! [0]
+
+//! [1] //! [2]
+int main(int argc, char *argv[])
+//! [1] //! [3] //! [4]
+{
+ QApplication app(argc, argv);
+//! [3]
+
+//! [5]
+ QTranslator translator;
+//! [5] //! [6]
+ translator.load("hellotr_la");
+//! [6] //! [7]
+ app.installTranslator(&translator);
+//! [4] //! [7]
+
+//! [8]
+ QPushButton hello(QPushButton::tr("Hello world!"));
+//! [8]
+ hello.resize(100, 30);
+
+ hello.show();
+ return app.exec();
+}
+//! [2]
diff --git a/examples/linguist/linguist.pro b/examples/linguist/linguist.pro
new file mode 100644
index 0000000000..69b6c83def
--- /dev/null
+++ b/examples/linguist/linguist.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = arrowpad \
+ hellotr \
+ trollprint
+
+# install
+sources.files = README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/linguist/trollprint/main.cpp b/examples/linguist/trollprint/main.cpp
new file mode 100644
index 0000000000..92f163002c
--- /dev/null
+++ b/examples/linguist/trollprint/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QString locale = QLocale::system().name();
+
+//! [0]
+ QTranslator translator;
+ translator.load(QString("trollprint_") + locale);
+ app.installTranslator(&translator);
+//! [0]
+
+ MainWindow mainWindow;
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/linguist/trollprint/mainwindow.cpp b/examples/linguist/trollprint/mainwindow.cpp
new file mode 100644
index 0000000000..4ea0db1733
--- /dev/null
+++ b/examples/linguist/trollprint/mainwindow.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "printpanel.h"
+
+MainWindow::MainWindow()
+{
+ printPanel = new PrintPanel;
+ setCentralWidget(printPanel);
+
+ createActions();
+ createMenus();
+
+//! [0]
+ setWindowTitle(tr("Troll Print 1.0"));
+//! [0]
+}
+
+void MainWindow::about()
+{
+ QMessageBox::information(this, tr("About Troll Print 1.0"),
+ tr("Troll Print 1.0.\n\n"
+ "Copyright 1999 Software, Inc."));
+}
+
+//! [1]
+void MainWindow::createActions()
+{
+//! [2]
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q", "Quit"));
+//! [2]
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ aboutAct->setShortcut(Qt::Key_F1);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+//! [1] //! [3]
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(exitAct);
+
+ menuBar()->addSeparator();
+
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [3]
diff --git a/examples/linguist/trollprint/mainwindow.h b/examples/linguist/trollprint/mainwindow.h
new file mode 100644
index 0000000000..8febe1eb4c
--- /dev/null
+++ b/examples/linguist/trollprint/mainwindow.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+QT_END_NAMESPACE
+class PrintPanel;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+
+ PrintPanel *printPanel;
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/linguist/trollprint/printpanel.cpp b/examples/linguist/trollprint/printpanel.cpp
new file mode 100644
index 0000000000..af1ff53193
--- /dev/null
+++ b/examples/linguist/trollprint/printpanel.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "printpanel.h"
+
+//! [0]
+PrintPanel::PrintPanel(QWidget *parent)
+ : QWidget(parent)
+{
+/*
+ QLabel *label = new QLabel(tr("<b>TROLL PRINT</b>"));
+ label->setAlignment(Qt::AlignCenter);
+*/
+//! [0]
+
+//! [1]
+ twoSidedGroupBox = new QGroupBox(tr("2-sided"));
+ twoSidedEnabledRadio = new QRadioButton(tr("Enabled"));
+ twoSidedDisabledRadio = new QRadioButton(tr("Disabled"));
+//! [1] //! [2]
+ twoSidedDisabledRadio->setChecked(true);
+
+ colorsGroupBox = new QGroupBox(tr("Colors"));
+ colorsEnabledRadio = new QRadioButton(tr("Enabled"));
+ colorsDisabledRadio = new QRadioButton(tr("Disabled"));
+//! [2]
+ colorsDisabledRadio->setChecked(true);
+
+ QHBoxLayout *twoSidedLayout = new QHBoxLayout;
+ twoSidedLayout->addWidget(twoSidedEnabledRadio);
+ twoSidedLayout->addWidget(twoSidedDisabledRadio);
+ twoSidedGroupBox->setLayout(twoSidedLayout);
+
+ QHBoxLayout *colorsLayout = new QHBoxLayout;
+ colorsLayout->addWidget(colorsEnabledRadio);
+ colorsLayout->addWidget(colorsDisabledRadio);
+ colorsGroupBox->setLayout(colorsLayout);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+/*
+ mainLayout->addWidget(label);
+*/
+ mainLayout->addWidget(twoSidedGroupBox);
+ mainLayout->addWidget(colorsGroupBox);
+ setLayout(mainLayout);
+}
diff --git a/examples/linguist/trollprint/printpanel.h b/examples/linguist/trollprint/printpanel.h
new file mode 100644
index 0000000000..45073199e5
--- /dev/null
+++ b/examples/linguist/trollprint/printpanel.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PRINTPANEL_H
+#define PRINTPANEL_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QGroupBox;
+class QRadioButton;
+QT_END_NAMESPACE
+
+//! [0]
+class PrintPanel : public QWidget
+{
+ Q_OBJECT
+//! [0]
+
+public:
+ PrintPanel(QWidget *parent = 0);
+
+private:
+ QGroupBox *twoSidedGroupBox;
+ QGroupBox *colorsGroupBox;
+ QRadioButton *twoSidedEnabledRadio;
+ QRadioButton *twoSidedDisabledRadio;
+ QRadioButton *colorsEnabledRadio;
+ QRadioButton *colorsDisabledRadio;
+};
+
+#endif
diff --git a/examples/linguist/trollprint/trollprint.pro b/examples/linguist/trollprint/trollprint.pro
new file mode 100644
index 0000000000..48ebacf293
--- /dev/null
+++ b/examples/linguist/trollprint/trollprint.pro
@@ -0,0 +1,14 @@
+HEADERS = mainwindow.h \
+ printpanel.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ printpanel.cpp
+TRANSLATIONS = trollprint_pt.ts
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/trollprint
+sources.files = $$SOURCES $$HEADERS $$TRANSLATIONS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/linguist/trollprint
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/linguist/trollprint/trollprint_pt.ts b/examples/linguist/trollprint/trollprint_pt.ts
new file mode 100644
index 0000000000..e5871bd087
--- /dev/null
+++ b/examples/linguist/trollprint/trollprint_pt.ts
@@ -0,0 +1,65 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>Troll Print 1.0</source>
+ <translation>Troll Imprimir 1.0</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Sair</translation>
+ </message>
+ <message>
+ <source>&amp;About</source>
+ <translation>&amp;Sobre</translation>
+ </message>
+ <message>
+ <source>About &amp;Qt</source>
+ <translation>Sobre &amp;Qt</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Arquivo</translation>
+ </message>
+ <message>
+ <source>&amp;Help</source>
+ <translation>A&amp;juda</translation>
+ </message>
+ <message>
+ <source>About Troll Print 1.0</source>
+ <translation>Sobre Troll Imprimir 1.0</translation>
+ </message>
+ <message>
+ <source>Troll Print 1.0.
+
+Copyright 1999 Software, Inc.</source>
+ <translation>Troll Imprimir 1.0
+
+Copyright 1999 Software, Inc.</translation>
+ </message>
+ <message>
+ <source>Ctrl+Q</source>
+ <comment>Quit</comment>
+ <translation>Ctrl+Q</translation>
+ </message>
+</context>
+<context>
+ <name>PrintPanel</name>
+ <message>
+ <source>2-sided</source>
+ <translation>2-lados</translation>
+ </message>
+ <message>
+ <source>Enabled</source>
+ <translation>Ativado</translation>
+ </message>
+ <message>
+ <source>Disabled</source>
+ <translation>Desativado</translation>
+ </message>
+ <message>
+ <source>Colors</source>
+ <translation>Cores</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/mainwindows/README b/examples/mainwindows/README
new file mode 100644
index 0000000000..15a6c23e4b
--- /dev/null
+++ b/examples/mainwindows/README
@@ -0,0 +1,40 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/mainwindows/application/application.pro b/examples/mainwindows/application/application.pro
new file mode 100644
index 0000000000..285568da85
--- /dev/null
+++ b/examples/mainwindows/application/application.pro
@@ -0,0 +1,14 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/application/application.qrc b/examples/mainwindows/application/application.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/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/mainwindows/application/images/copy.png b/examples/mainwindows/application/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/mainwindows/application/images/copy.png
Binary files differ
diff --git a/examples/mainwindows/application/images/cut.png b/examples/mainwindows/application/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/mainwindows/application/images/cut.png
Binary files differ
diff --git a/examples/mainwindows/application/images/new.png b/examples/mainwindows/application/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/mainwindows/application/images/new.png
Binary files differ
diff --git a/examples/mainwindows/application/images/open.png b/examples/mainwindows/application/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/mainwindows/application/images/open.png
Binary files differ
diff --git a/examples/mainwindows/application/images/paste.png b/examples/mainwindows/application/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/mainwindows/application/images/paste.png
Binary files differ
diff --git a/examples/mainwindows/application/images/save.png b/examples/mainwindows/application/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/mainwindows/application/images/save.png
Binary files differ
diff --git a/examples/mainwindows/application/main.cpp b/examples/mainwindows/application/main.cpp
new file mode 100644
index 0000000000..9a9dc9ca76
--- /dev/null
+++ b/examples/mainwindows/application/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [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/mainwindows/application/mainwindow.cpp b/examples/mainwindows/application/mainwindow.cpp
new file mode 100644
index 0000000000..4ebc5c169e
--- /dev/null
+++ b/examples/mainwindows/application/mainwindow.cpp
@@ -0,0 +1,392 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtGui>
+
+#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/mainwindows/application/mainwindow.h b/examples/mainwindows/application/mainwindow.h
new file mode 100644
index 0000000000..9d40d30026
--- /dev/null
+++ b/examples/mainwindows/application/mainwindow.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/dockwidgets/dockwidgets.pro b/examples/mainwindows/dockwidgets/dockwidgets.pro
new file mode 100644
index 0000000000..3485ca5e02
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/dockwidgets.pro
@@ -0,0 +1,12 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/dockwidgets/dockwidgets.qrc b/examples/mainwindows/dockwidgets/dockwidgets.qrc
new file mode 100644
index 0000000000..968feac7ea
--- /dev/null
+++ b/examples/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/mainwindows/dockwidgets/images/new.png b/examples/mainwindows/dockwidgets/images/new.png
new file mode 100644
index 0000000000..dd795cfffc
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/images/new.png
Binary files differ
diff --git a/examples/mainwindows/dockwidgets/images/print.png b/examples/mainwindows/dockwidgets/images/print.png
new file mode 100644
index 0000000000..2afb769ee2
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/images/print.png
Binary files differ
diff --git a/examples/mainwindows/dockwidgets/images/save.png b/examples/mainwindows/dockwidgets/images/save.png
new file mode 100644
index 0000000000..46eac82ad1
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/images/save.png
Binary files differ
diff --git a/examples/mainwindows/dockwidgets/images/undo.png b/examples/mainwindows/dockwidgets/images/undo.png
new file mode 100644
index 0000000000..eee23d24a3
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/images/undo.png
Binary files differ
diff --git a/examples/mainwindows/dockwidgets/main.cpp b/examples/mainwindows/dockwidgets/main.cpp
new file mode 100644
index 0000000000..5c846a4dad
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/dockwidgets/mainwindow.cpp b/examples/mainwindows/dockwidgets/mainwindow.cpp
new file mode 100644
index 0000000000..296eec2242
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/mainwindow.cpp
@@ -0,0 +1,342 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtGui>
+
+#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/mainwindows/dockwidgets/mainwindow.h b/examples/mainwindows/dockwidgets/mainwindow.h
new file mode 100644
index 0000000000..6ac8ff3883
--- /dev/null
+++ b/examples/mainwindows/dockwidgets/mainwindow.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/mainwindows.pro b/examples/mainwindows/mainwindows.pro
new file mode 100644
index 0000000000..d44f9f0b49
--- /dev/null
+++ b/examples/mainwindows/mainwindows.pro
@@ -0,0 +1,19 @@
+TEMPLATE = subdirs
+SUBDIRS = application \
+ dockwidgets \
+ mdi \
+ menus \
+ recentfiles \
+ sdi
+
+symbian: SUBDIRS = \
+ menus
+
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/mdi/images/copy.png b/examples/mainwindows/mdi/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/mainwindows/mdi/images/copy.png
Binary files differ
diff --git a/examples/mainwindows/mdi/images/cut.png b/examples/mainwindows/mdi/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/mainwindows/mdi/images/cut.png
Binary files differ
diff --git a/examples/mainwindows/mdi/images/new.png b/examples/mainwindows/mdi/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/mainwindows/mdi/images/new.png
Binary files differ
diff --git a/examples/mainwindows/mdi/images/open.png b/examples/mainwindows/mdi/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/mainwindows/mdi/images/open.png
Binary files differ
diff --git a/examples/mainwindows/mdi/images/paste.png b/examples/mainwindows/mdi/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/mainwindows/mdi/images/paste.png
Binary files differ
diff --git a/examples/mainwindows/mdi/images/save.png b/examples/mainwindows/mdi/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/mainwindows/mdi/images/save.png
Binary files differ
diff --git a/examples/mainwindows/mdi/main.cpp b/examples/mainwindows/mdi/main.cpp
new file mode 100644
index 0000000000..1a10a19619
--- /dev/null
+++ b/examples/mainwindows/mdi/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/mdi/mainwindow.cpp b/examples/mainwindows/mdi/mainwindow.cpp
new file mode 100644
index 0000000000..956eabb230
--- /dev/null
+++ b/examples/mainwindows/mdi/mainwindow.cpp
@@ -0,0 +1,397 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+}
+
+void MainWindow::cut()
+{
+ if (activeMdiChild())
+ activeMdiChild()->cut();
+}
+
+void MainWindow::copy()
+{
+ if (activeMdiChild())
+ activeMdiChild()->copy();
+}
+
+void MainWindow::paste()
+{
+ if (activeMdiChild())
+ activeMdiChild()->paste();
+}
+
+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);
+ pasteAct->setEnabled(hasMdiChild);
+ closeAct->setEnabled(hasMdiChild);
+ closeAllAct->setEnabled(hasMdiChild);
+ tileAct->setEnabled(hasMdiChild);
+ cascadeAct->setEnabled(hasMdiChild);
+ nextAct->setEnabled(hasMdiChild);
+ previousAct->setEnabled(hasMdiChild);
+ separatorAct->setVisible(hasMdiChild);
+
+ bool hasSelection = (activeMdiChild() &&
+ activeMdiChild()->textCursor().hasSelection());
+ cutAct->setEnabled(hasSelection);
+ copyAct->setEnabled(hasSelection);
+}
+
+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);
+
+ connect(child, SIGNAL(copyAvailable(bool)),
+ cutAct, SLOT(setEnabled(bool)));
+ connect(child, SIGNAL(copyAvailable(bool)),
+ copyAct, SLOT(setEnabled(bool)));
+
+ 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]
+
+ 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()));
+
+ 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"));
+ editMenu->addAction(cutAct);
+ editMenu->addAction(copyAct);
+ editMenu->addAction(pasteAct);
+
+ 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);
+
+ 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("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/mainwindows/mdi/mainwindow.h b/examples/mainwindows/mdi/mainwindow.h
new file mode 100644
index 0000000000..906dee9bca
--- /dev/null
+++ b/examples/mainwindows/mdi/mainwindow.h
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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();
+ void cut();
+ void copy();
+ void paste();
+ 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;
+ QAction *cutAct;
+ QAction *copyAct;
+ QAction *pasteAct;
+ QAction *closeAct;
+ QAction *closeAllAct;
+ QAction *tileAct;
+ QAction *cascadeAct;
+ QAction *nextAct;
+ QAction *previousAct;
+ QAction *separatorAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/mainwindows/mdi/mdi.pro b/examples/mainwindows/mdi/mdi.pro
new file mode 100644
index 0000000000..3eedff1949
--- /dev/null
+++ b/examples/mainwindows/mdi/mdi.pro
@@ -0,0 +1,14 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/mdi/mdi.qrc b/examples/mainwindows/mdi/mdi.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/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/mainwindows/mdi/mdichild.cpp b/examples/mainwindows/mdi/mdichild.cpp
new file mode 100644
index 0000000000..0382b27e23
--- /dev/null
+++ b/examples/mainwindows/mdi/mdichild.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/mainwindows/mdi/mdichild.h b/examples/mainwindows/mdi/mdichild.h
new file mode 100644
index 0000000000..e136d7f9ae
--- /dev/null
+++ b/examples/mainwindows/mdi/mdichild.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/menus/main.cpp b/examples/mainwindows/menus/main.cpp
new file mode 100644
index 0000000000..01c8adae53
--- /dev/null
+++ b/examples/mainwindows/menus/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/menus/mainwindow.cpp b/examples/mainwindows/menus/mainwindow.cpp
new file mode 100644
index 0000000000..cae81f6b71
--- /dev/null
+++ b/examples/mainwindows/menus/mainwindow.cpp
@@ -0,0 +1,370 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+ setLineSpacingAct->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/mainwindows/menus/mainwindow.h b/examples/mainwindows/menus/mainwindow.h
new file mode 100644
index 0000000000..58b33fa257
--- /dev/null
+++ b/examples/mainwindows/menus/mainwindow.h
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/menus/menus.pro b/examples/mainwindows/menus/menus.pro
new file mode 100644
index 0000000000..dc762ff44d
--- /dev/null
+++ b/examples/mainwindows/menus/menus.pro
@@ -0,0 +1,14 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000CF66
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/mainwindows/recentfiles/main.cpp b/examples/mainwindows/recentfiles/main.cpp
new file mode 100644
index 0000000000..3bbf0137c1
--- /dev/null
+++ b/examples/mainwindows/recentfiles/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/recentfiles/mainwindow.cpp b/examples/mainwindows/recentfiles/mainwindow.cpp
new file mode 100644
index 0000000000..623c4a375c
--- /dev/null
+++ b/examples/mainwindows/recentfiles/mainwindow.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/mainwindows/recentfiles/mainwindow.h b/examples/mainwindows/recentfiles/mainwindow.h
new file mode 100644
index 0000000000..8c41502bf1
--- /dev/null
+++ b/examples/mainwindows/recentfiles/mainwindow.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/recentfiles/recentfiles.pro b/examples/mainwindows/recentfiles/recentfiles.pro
new file mode 100644
index 0000000000..b4cf79b630
--- /dev/null
+++ b/examples/mainwindows/recentfiles/recentfiles.pro
@@ -0,0 +1,11 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/sdi/images/copy.png b/examples/mainwindows/sdi/images/copy.png
new file mode 100644
index 0000000000..2aeb28288f
--- /dev/null
+++ b/examples/mainwindows/sdi/images/copy.png
Binary files differ
diff --git a/examples/mainwindows/sdi/images/cut.png b/examples/mainwindows/sdi/images/cut.png
new file mode 100644
index 0000000000..54638e9386
--- /dev/null
+++ b/examples/mainwindows/sdi/images/cut.png
Binary files differ
diff --git a/examples/mainwindows/sdi/images/new.png b/examples/mainwindows/sdi/images/new.png
new file mode 100644
index 0000000000..12131b0100
--- /dev/null
+++ b/examples/mainwindows/sdi/images/new.png
Binary files differ
diff --git a/examples/mainwindows/sdi/images/open.png b/examples/mainwindows/sdi/images/open.png
new file mode 100644
index 0000000000..45fa2883a7
--- /dev/null
+++ b/examples/mainwindows/sdi/images/open.png
Binary files differ
diff --git a/examples/mainwindows/sdi/images/paste.png b/examples/mainwindows/sdi/images/paste.png
new file mode 100644
index 0000000000..c14425cad1
--- /dev/null
+++ b/examples/mainwindows/sdi/images/paste.png
Binary files differ
diff --git a/examples/mainwindows/sdi/images/save.png b/examples/mainwindows/sdi/images/save.png
new file mode 100644
index 0000000000..daba865faf
--- /dev/null
+++ b/examples/mainwindows/sdi/images/save.png
Binary files differ
diff --git a/examples/mainwindows/sdi/main.cpp b/examples/mainwindows/sdi/main.cpp
new file mode 100644
index 0000000000..0fb8a0388d
--- /dev/null
+++ b/examples/mainwindows/sdi/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/sdi/mainwindow.cpp b/examples/mainwindows/sdi/mainwindow.cpp
new file mode 100644
index 0000000000..f881118899
--- /dev/null
+++ b/examples/mainwindows/sdi/mainwindow.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/mainwindows/sdi/mainwindow.h b/examples/mainwindows/sdi/mainwindow.h
new file mode 100644
index 0000000000..c8ca63f38b
--- /dev/null
+++ b/examples/mainwindows/sdi/mainwindow.h
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/mainwindows/sdi/sdi.pro b/examples/mainwindows/sdi/sdi.pro
new file mode 100644
index 0000000000..1ca9746c9e
--- /dev/null
+++ b/examples/mainwindows/sdi/sdi.pro
@@ -0,0 +1,12 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/mainwindows/sdi/sdi.qrc b/examples/mainwindows/sdi/sdi.qrc
new file mode 100644
index 0000000000..0a776fab4d
--- /dev/null
+++ b/examples/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/network/README b/examples/network/README
new file mode 100644
index 0000000000..23721df4c3
--- /dev/null
+++ b/examples/network/README
@@ -0,0 +1,40 @@
+Qt is provided with an extensive set of network classes to support both
+client-based and server side network programming.
+
+These examples demonstrate the fundamental aspects of network programming
+with Qt.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp
new file mode 100644
index 0000000000..942b19ce01
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor.cpp
@@ -0,0 +1,423 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "bearermonitor.h"
+#include "sessionwidget.h"
+
+#include <QtCore/QDebug>
+
+#ifdef Q_OS_WIN
+#include <winsock2.h>
+#undef interface
+
+#ifndef NS_NLA
+#define NS_NLA 15
+#endif
+#endif
+
+BearerMonitor::BearerMonitor(QWidget *parent)
+: QWidget(parent)
+{
+ setupUi(this);
+#ifdef MAEMO_UI
+ newSessionButton->hide();
+ deleteSessionButton->hide();
+#else
+ delete tabWidget->currentWidget();
+ sessionGroup->hide();
+#endif
+#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(MAEMO_UI)
+ setWindowState(Qt::WindowMaximized);
+#endif
+ updateConfigurations();
+ onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty());
+ QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration();
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem *item = treeWidget->topLevelItem(i);
+
+ if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) {
+ treeWidget->setCurrentItem(item);
+ showConfigurationFor(item);
+ break;
+ }
+ }
+ connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool)));
+ connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
+ this, SLOT(configurationAdded(const QNetworkConfiguration&)));
+ connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
+ this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
+ connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
+ this, SLOT(configurationChanged(const QNetworkConfiguration)));
+ connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations()));
+
+#ifdef Q_OS_WIN
+ connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork()));
+ connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork()));
+#else
+ nlaGroup->hide();
+#endif
+
+ connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
+ this, SLOT(createSessionFor(QTreeWidgetItem*)));
+
+ connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
+ this, SLOT(showConfigurationFor(QTreeWidgetItem*)));
+
+ connect(newSessionButton, SIGNAL(clicked()),
+ this, SLOT(createNewSession()));
+#ifndef MAEMO_UI
+ connect(deleteSessionButton, SIGNAL(clicked()),
+ this, SLOT(deleteSession()));
+#endif
+ connect(scanButton, SIGNAL(clicked()),
+ this, SLOT(performScan()));
+
+ // Just in case update all configurations so that all
+ // configurations are up to date.
+ manager.updateConfigurations();
+}
+
+BearerMonitor::~BearerMonitor()
+{
+}
+
+static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &config)
+{
+ item->setText(0, config.name());
+ item->setData(0, Qt::UserRole, config.identifier());
+
+ QFont font = item->font(1);
+ font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active);
+ item->setFont(0, font);
+}
+
+void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent)
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem;
+ updateItem(item, config);
+
+ if (parent)
+ parent->addChild(item);
+ else
+ treeWidget->addTopLevelItem(item);
+
+ if (config.type() == QNetworkConfiguration::ServiceNetwork) {
+ foreach (const QNetworkConfiguration &child, config.children())
+ configurationAdded(child, item);
+ }
+}
+
+void BearerMonitor::configurationRemoved(const QNetworkConfiguration &config)
+{
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem *item = treeWidget->topLevelItem(i);
+
+ if (item->data(0, Qt::UserRole).toString() == config.identifier()) {
+ delete item;
+ break;
+ }
+ }
+}
+
+void BearerMonitor::configurationChanged(const QNetworkConfiguration &config)
+{
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem *item = treeWidget->topLevelItem(i);
+
+ if (item->data(0, Qt::UserRole).toString() == config.identifier()) {
+ updateItem(item, config);
+
+ if (config.type() == QNetworkConfiguration::ServiceNetwork)
+ updateSnapConfiguration(item, config);
+
+ if (item == treeWidget->currentItem())
+ showConfigurationFor(item);
+
+ break;
+ }
+ }
+}
+
+void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap)
+{
+ QMap<QString, QTreeWidgetItem *> itemMap;
+ foreach (QTreeWidgetItem *item, parent->takeChildren())
+ itemMap.insert(item->data(0, Qt::UserRole).toString(), item);
+
+ QList<QNetworkConfiguration> allConfigurations = snap.children();
+
+ while (!allConfigurations.isEmpty()) {
+ QNetworkConfiguration config = allConfigurations.takeFirst();
+
+ QTreeWidgetItem *item = itemMap.take(config.identifier());
+ if (item) {
+ updateItem(item, config);
+
+ parent->addChild(item);
+
+ if (config.type() == QNetworkConfiguration::ServiceNetwork)
+ updateSnapConfiguration(item, config);
+ } else {
+ configurationAdded(config, parent);
+ }
+ }
+
+ qDeleteAll(itemMap);
+}
+
+void BearerMonitor::updateConfigurations()
+{
+ progressBar->hide();
+ scanButton->show();
+
+ // Just in case update online state, on Symbian platform
+ // WLAN scan needs to be triggered initially to have their true state.
+ onlineStateChanged(manager.isOnline());
+
+ QList<QTreeWidgetItem *> items = treeWidget->findItems(QLatin1String("*"), Qt::MatchWildcard);
+ QMap<QString, QTreeWidgetItem *> itemMap;
+ while (!items.isEmpty()) {
+ QTreeWidgetItem *item = items.takeFirst();
+ itemMap.insert(item->data(0, Qt::UserRole).toString(), item);
+ }
+
+ QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration();
+ QTreeWidgetItem *defaultItem = itemMap.take(defaultConfiguration.identifier());
+
+ if (defaultItem) {
+ updateItem(defaultItem, defaultConfiguration);
+
+ if (defaultConfiguration.type() == QNetworkConfiguration::ServiceNetwork)
+ updateSnapConfiguration(defaultItem, defaultConfiguration);
+ } else if (defaultConfiguration.isValid()) {
+ configurationAdded(defaultConfiguration);
+ }
+
+ QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations();
+
+ while (!allConfigurations.isEmpty()) {
+ QNetworkConfiguration config = allConfigurations.takeFirst();
+
+ if (config.identifier() == defaultConfiguration.identifier())
+ continue;
+
+ QTreeWidgetItem *item = itemMap.take(config.identifier());
+ if (item) {
+ updateItem(item, config);
+
+ if (config.type() == QNetworkConfiguration::ServiceNetwork)
+ updateSnapConfiguration(item, config);
+ } else {
+ configurationAdded(config);
+ }
+ }
+
+ qDeleteAll(itemMap);
+}
+
+void BearerMonitor::onlineStateChanged(bool isOnline)
+{
+ if (isOnline)
+ onlineState->setText(tr("Online"));
+ else
+ onlineState->setText(tr("Offline"));
+}
+
+#ifdef Q_OS_WIN
+void BearerMonitor::registerNetwork()
+{
+ QTreeWidgetItem *item = treeWidget->currentItem();
+ if (!item) return;
+
+ QNetworkConfiguration configuration =
+ manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString());
+
+ const QString name = configuration.name();
+
+ qDebug() << "Registering" << name << "with system";
+
+ WSAQUERYSET networkInfo;
+ memset(&networkInfo, 0, sizeof(networkInfo));
+ networkInfo.dwSize = sizeof(networkInfo);
+ networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16();
+ networkInfo.dwNameSpace = NS_NLA;
+
+ if (WSASetService(&networkInfo, RNRSERVICE_REGISTER, 0) == SOCKET_ERROR)
+ qDebug() << "WSASetService(RNRSERVICE_REGISTER) returned" << WSAGetLastError();
+}
+
+void BearerMonitor::unregisterNetwork()
+{
+ QTreeWidgetItem *item = treeWidget->currentItem();
+ if (!item) return;
+
+ QNetworkConfiguration configuration =
+ manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString());
+
+ const QString name = configuration.name();
+
+ qDebug() << "Unregistering" << name << "with system";
+
+ WSAQUERYSET networkInfo;
+ memset(&networkInfo, 0, sizeof(networkInfo));
+ networkInfo.dwSize = sizeof(networkInfo);
+ networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16();
+ networkInfo.dwNameSpace = NS_NLA;
+
+ if (WSASetService(&networkInfo, RNRSERVICE_DELETE, 0) == SOCKET_ERROR)
+ qDebug() << "WSASetService(RNRSERVICE_DELETE) returned" << WSAGetLastError();
+}
+#endif
+
+void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item)
+{
+ QString identifier;
+
+ if (item)
+ identifier = item->data(0, Qt::UserRole).toString();
+
+ QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier);
+
+ switch (conf.state()) {
+ case QNetworkConfiguration::Active:
+ configurationState->setText(tr("Active"));
+ break;
+ case QNetworkConfiguration::Discovered:
+ configurationState->setText(tr("Discovered"));
+ break;
+ case QNetworkConfiguration::Defined:
+ configurationState->setText(tr("Defined"));
+ break;
+ case QNetworkConfiguration::Undefined:
+ configurationState->setText(tr("Undefined"));
+ break;
+ default:
+ configurationState->setText(QString());
+ }
+
+ switch (conf.type()) {
+ case QNetworkConfiguration::InternetAccessPoint:
+ configurationType->setText(tr("Internet Access Point"));
+ break;
+ case QNetworkConfiguration::ServiceNetwork:
+ configurationType->setText(tr("Service Network"));
+ break;
+ case QNetworkConfiguration::UserChoice:
+ configurationType->setText(tr("User Choice"));
+ break;
+ case QNetworkConfiguration::Invalid:
+ configurationType->setText(tr("Invalid"));
+ break;
+ default:
+ configurationType->setText(QString());
+ }
+
+ switch (conf.purpose()) {
+ case QNetworkConfiguration::UnknownPurpose:
+ configurationPurpose->setText(tr("Unknown"));
+ break;
+ case QNetworkConfiguration::PublicPurpose:
+ configurationPurpose->setText(tr("Public"));
+ break;
+ case QNetworkConfiguration::PrivatePurpose:
+ configurationPurpose->setText(tr("Private"));
+ break;
+ case QNetworkConfiguration::ServiceSpecificPurpose:
+ configurationPurpose->setText(tr("Service Specific"));
+ break;
+ default:
+ configurationPurpose->setText(QString());
+ }
+
+ configurationIdentifier->setText(conf.identifier());
+
+ configurationRoaming->setText(conf.isRoamingAvailable() ? tr("Available") : tr("Not available"));
+
+ configurationChildren->setText(QString::number(conf.children().count()));
+
+ configurationName->setText(conf.name());
+}
+
+void BearerMonitor::createSessionFor(QTreeWidgetItem *item)
+{
+ const QString identifier = item->data(0, Qt::UserRole).toString();
+
+ QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier);
+
+ SessionWidget *session = new SessionWidget(conf);
+
+ tabWidget->addTab(session, conf.name());
+
+#ifndef MAEMO_UI
+ sessionGroup->show();
+#endif
+
+ sessionWidgets.append(session);
+}
+
+void BearerMonitor::createNewSession()
+{
+ QTreeWidgetItem *item = treeWidget->currentItem();
+ if (!item) return;
+
+ createSessionFor(item);
+}
+
+#ifndef MAEMO_UI
+void BearerMonitor::deleteSession()
+{
+ SessionWidget *session = qobject_cast<SessionWidget *>(tabWidget->currentWidget());
+ if (session) {
+ sessionWidgets.removeAll(session);
+
+ delete session;
+
+ if (tabWidget->count() == 0)
+ sessionGroup->hide();
+ }
+}
+#endif
+
+void BearerMonitor::performScan()
+{
+ scanButton->hide();
+ progressBar->show();
+ manager.updateConfigurations();
+}
diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h
new file mode 100644
index 0000000000..a06522fafa
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BEARERMONITOR_H
+#define BEARERMONITOR_H
+
+#include <qnetworkconfigmanager.h>
+#include <qnetworksession.h>
+#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE)
+#include "ui_bearermonitor_240_320.h"
+#elif defined(MAEMO_UI)
+#include "ui_bearermonitor_maemo.h"
+#else
+#include "ui_bearermonitor_640_480.h"
+#endif
+
+QT_USE_NAMESPACE
+
+class SessionWidget;
+
+class BearerMonitor : public QWidget, public Ui_BearerMonitor
+{
+ Q_OBJECT
+
+public:
+ BearerMonitor(QWidget *parent = 0);
+ ~BearerMonitor();
+
+private slots:
+ void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0);
+ void configurationRemoved(const QNetworkConfiguration &config);
+ void configurationChanged(const QNetworkConfiguration &config);
+ void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap);
+ void updateConfigurations();
+
+ void onlineStateChanged(bool isOnline);
+
+#ifdef Q_OS_WIN
+ void registerNetwork();
+ void unregisterNetwork();
+#endif
+
+ void showConfigurationFor(QTreeWidgetItem *item);
+
+ void createSessionFor(QTreeWidgetItem *item);
+ void createNewSession();
+#ifndef MAEMO_UI
+ void deleteSession();
+#endif
+ void performScan();
+
+private:
+ QNetworkConfigurationManager manager;
+ QList<SessionWidget *> sessionWidgets;
+};
+
+#endif //BEARERMONITOR_H
diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro
new file mode 100644
index 0000000000..bd9bd68e5c
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor.pro
@@ -0,0 +1,26 @@
+TARGET = bearermonitor
+QT = core gui network
+
+HEADERS = sessionwidget.h \
+ bearermonitor.h
+
+SOURCES = main.cpp \
+ bearermonitor.cpp \
+ sessionwidget.cpp
+
+maemo5|maemo6|linux-g++-maemo {
+ DEFINES += MAEMO_UI
+ FORMS = bearermonitor_maemo.ui \
+ sessionwidget_maemo.ui
+} else {
+ FORMS = bearermonitor_240_320.ui \
+ bearermonitor_640_480.ui \
+ sessionwidget.ui
+}
+
+win32:!wince*:LIBS += -lws2_32
+wince*:LIBS += -lws2
+
+CONFIG += console
+
+symbian:TARGET.CAPABILITY = NetworkServices ReadUserData
diff --git a/examples/network/bearermonitor/bearermonitor_240_320.ui b/examples/network/bearermonitor/bearermonitor_240_320.ui
new file mode 100644
index 0000000000..93cfc5e0e3
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor_240_320.ui
@@ -0,0 +1,420 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>BearerMonitor</class>
+ <widget class="QWidget" name="BearerMonitor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>240</width>
+ <height>320</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>BearerMonitor</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>-274</y>
+ <width>206</width>
+ <height>576</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QGroupBox" name="systemState">
+ <property name="title">
+ <string>System State</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" name="onlineStateLayout">
+ <item>
+ <widget class="QLabel" name="onlineStateLabel">
+ <property name="text">
+ <string>Online State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="onlineState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Configurations</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="configurationNameLayout">
+ <item>
+ <widget class="QLabel" name="configurationNameLabel">
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationName">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationStateLayout">
+ <item>
+ <widget class="QLabel" name="configurationStateLabel">
+ <property name="text">
+ <string>State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationTypeLayout">
+ <item>
+ <widget class="QLabel" name="configurationTypeLabel">
+ <property name="text">
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Invalid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationPurposeLayout">
+ <item>
+ <widget class="QLabel" name="configurationPurposeLabel">
+ <property name="text">
+ <string>Purpose:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationPurpose">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Unknown</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationIdentifierLayout">
+ <item>
+ <widget class="QLabel" name="configurationIdentifierLabel">
+ <property name="text">
+ <string>Identifier:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationIdentifier">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationRoamingLayout">
+ <item>
+ <widget class="QLabel" name="configurationRoamingLabel">
+ <property name="text">
+ <string>Roaming:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationRoaming">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationChildrenLayout">
+ <item>
+ <widget class="QLabel" name="configurationChildrenLabel">
+ <property name="text">
+ <string>Children:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationChildren">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="nlaGroup">
+ <property name="title">
+ <string>Network Location Awareness</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="registerButton">
+ <property name="text">
+ <string>Register</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="unregisterButton">
+ <property name="text">
+ <string>Unregister</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="newSessionButton">
+ <property name="text">
+ <string>New Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteSessionButton">
+ <property name="text">
+ <string>Delete Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="scanButton">
+ <property name="text">
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>-1</number>
+ </property>
+ <property name="textVisible">
+ <bool>false</bool>
+ </property>
+ <property name="invertedAppearance">
+ <bool>false</bool>
+ </property>
+ <property name="format">
+ <string>%p%</string>
+ </property>
+ </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>
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="sessionGroup">
+ <property name="title">
+ <string>Sessions</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Session 1</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/bearermonitor/bearermonitor_640_480.ui b/examples/network/bearermonitor/bearermonitor_640_480.ui
new file mode 100644
index 0000000000..52866bc9cd
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor_640_480.ui
@@ -0,0 +1,386 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>BearerMonitor</class>
+ <widget class="QWidget" name="BearerMonitor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>640</width>
+ <height>515</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>BearerMonitor</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="systemState">
+ <property name="title">
+ <string>System State</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" name="onlineStateLayout">
+ <item>
+ <widget class="QLabel" name="onlineStateLabel">
+ <property name="text">
+ <string>Online State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="onlineState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Configurations</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="configurationNameLayout">
+ <item>
+ <widget class="QLabel" name="configurationNameLabel">
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationName">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationStateLayout">
+ <item>
+ <widget class="QLabel" name="configurationStateLabel">
+ <property name="text">
+ <string>State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationTypeLayout">
+ <item>
+ <widget class="QLabel" name="configurationTypeLabel">
+ <property name="text">
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Invalid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationPurposeLayout">
+ <item>
+ <widget class="QLabel" name="configurationPurposeLabel">
+ <property name="text">
+ <string>Purpose:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationPurpose">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Unknown</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationIdentifierLayout">
+ <item>
+ <widget class="QLabel" name="configurationIdentifierLabel">
+ <property name="text">
+ <string>Identifier:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationIdentifier">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationRoamingLayout">
+ <item>
+ <widget class="QLabel" name="configurationRoamingLabel">
+ <property name="text">
+ <string>Roaming:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationRoaming">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationChildrenLayout">
+ <item>
+ <widget class="QLabel" name="configurationChildrenLabel">
+ <property name="text">
+ <string>Children:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationChildren">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="nlaGroup">
+ <property name="title">
+ <string>Network Location Awareness</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="registerButton">
+ <property name="text">
+ <string>Register</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="unregisterButton">
+ <property name="text">
+ <string>Unregister</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="newSessionButton">
+ <property name="text">
+ <string>New Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteSessionButton">
+ <property name="text">
+ <string>Delete Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="scanButton">
+ <property name="text">
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>-1</number>
+ </property>
+ <property name="textVisible">
+ <bool>false</bool>
+ </property>
+ <property name="invertedAppearance">
+ <bool>false</bool>
+ </property>
+ <property name="format">
+ <string>%p%</string>
+ </property>
+ </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>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QGroupBox" name="sessionGroup">
+ <property name="title">
+ <string>Sessions</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Session 1</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/bearermonitor/bearermonitor_maemo.ui b/examples/network/bearermonitor/bearermonitor_maemo.ui
new file mode 100644
index 0000000000..9c72bfd5b1
--- /dev/null
+++ b/examples/network/bearermonitor/bearermonitor_maemo.ui
@@ -0,0 +1,369 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>BearerMonitor</class>
+ <widget class="QWidget" name="BearerMonitor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>612</width>
+ <height>555</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>BearerMonitor</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
+ <item>
+ <widget class="QGroupBox" name="systemState">
+ <property name="title">
+ <string>System State</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="onlineStateLabel">
+ <property name="text">
+ <string>Online State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="onlineState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="configurations">
+ <property name="title">
+ <string>Configurations &amp;&amp; Sessions</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <property name="usesScrollButtons">
+ <bool>false</bool>
+ </property>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Configurations</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QTreeWidget" name="treeWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="configurationNameLayout">
+ <item>
+ <widget class="QLabel" name="configurationNameLabel">
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationName">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationStateLayout">
+ <item>
+ <widget class="QLabel" name="configurationStateLabel">
+ <property name="text">
+ <string>State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationTypeLayout">
+ <item>
+ <widget class="QLabel" name="configurationTypeLabel">
+ <property name="text">
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationType">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Invalid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationPurposeLayout">
+ <item>
+ <widget class="QLabel" name="configurationPurposeLabel">
+ <property name="text">
+ <string>Purpose:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationPurpose">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Unknown</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationIdentifierLayout">
+ <item>
+ <widget class="QLabel" name="configurationIdentifierLabel">
+ <property name="text">
+ <string>Identifier:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationIdentifier">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationRoamingLayout">
+ <item>
+ <widget class="QLabel" name="configurationRoamingLabel">
+ <property name="text">
+ <string>Roaming:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationRoaming">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationChildrenLayout">
+ <item>
+ <widget class="QLabel" name="configurationChildrenLabel">
+ <property name="text">
+ <string>Children:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configurationChildren">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="nlaGroup">
+ <property name="title">
+ <string>Network Location Awareness</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="registerButton">
+ <property name="text">
+ <string>Register</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="unregisterButton">
+ <property name="text">
+ <string>Unregister</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="newSessionButton">
+ <property name="text">
+ <string>New Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteSessionButton">
+ <property name="text">
+ <string>Delete Session</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="scanButton">
+ <property name="text">
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>23280</number>
+ </property>
+ <property name="textVisible">
+ <bool>false</bool>
+ </property>
+ <property name="invertedAppearance">
+ <bool>false</bool>
+ </property>
+ <property name="format">
+ <string>%p%</string>
+ </property>
+ </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>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp
new file mode 100644
index 0000000000..1358033fc2
--- /dev/null
+++ b/examples/network/bearermonitor/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMainWindow>
+
+#include "bearermonitor.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QMainWindow mainWindow;
+
+ BearerMonitor monitor;
+
+ mainWindow.setCentralWidget(&monitor);
+ mainWindow.show();
+
+ return app.exec();
+}
+
diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp
new file mode 100644
index 0000000000..eed3660ca0
--- /dev/null
+++ b/examples/network/bearermonitor/sessionwidget.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "sessionwidget.h"
+#include "qnetworkconfigmanager.h"
+
+SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent)
+: QWidget(parent), statsTimer(-1)
+{
+ setupUi(this);
+
+#ifdef QT_NO_NETWORKINTERFACE
+ interfaceName->setVisible(false);
+ interfaceNameLabel->setVisible(false);
+ interfaceGuid->setVisible(false);
+ interfaceGuidLabel->setVisible(false);
+#endif
+
+ session = new QNetworkSession(config, this);
+
+ connect(session, SIGNAL(stateChanged(QNetworkSession::State)),
+ this, SLOT(updateSession()));
+ connect(session, SIGNAL(error(QNetworkSession::SessionError)),
+ this, SLOT(updateSessionError(QNetworkSession::SessionError)));
+
+ updateSession();
+
+ sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0')));
+
+ configuration->setText(session->configuration().name());
+
+ connect(openSessionButton, SIGNAL(clicked()),
+ this, SLOT(openSession()));
+ connect(openSyncSessionButton, SIGNAL(clicked()),
+ this, SLOT(openSyncSession()));
+ connect(closeSessionButton, SIGNAL(clicked()),
+ this, SLOT(closeSession()));
+ connect(stopSessionButton, SIGNAL(clicked()),
+ this, SLOT(stopSession()));
+#ifdef MAEMO_UI
+ connect(deleteSessionButton, SIGNAL(clicked()),
+ this, SLOT(deleteSession()));
+#endif
+}
+
+SessionWidget::~SessionWidget()
+{
+ delete session;
+}
+
+void SessionWidget::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == statsTimer) {
+ rxData->setText(QString::number(session->bytesReceived()));
+ txData->setText(QString::number(session->bytesWritten()));
+ activeTime->setText(QString::number(session->activeTime()));
+ }
+}
+
+#ifdef MAEMO_UI
+void SessionWidget::deleteSession()
+{
+ delete this;
+}
+#endif
+
+void SessionWidget::updateSession()
+{
+ updateSessionState(session->state());
+
+ if (session->state() == QNetworkSession::Connected)
+ statsTimer = startTimer(1000);
+ else if (statsTimer != -1)
+ killTimer(statsTimer);
+
+ if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint)
+ bearer->setText(session->configuration().bearerTypeName());
+ else {
+ QNetworkConfigurationManager mgr;
+ QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString());
+ bearer->setText(c.bearerTypeName());
+ }
+
+#ifndef QT_NO_NETWORKINTERFACE
+ interfaceName->setText(session->interface().humanReadableName());
+ interfaceGuid->setText(session->interface().name());
+#endif
+}
+
+void SessionWidget::openSession()
+{
+ clearError();
+ session->open();
+ updateSession();
+}
+
+void SessionWidget::openSyncSession()
+{
+ clearError();
+ session->open();
+ session->waitForOpened();
+ updateSession();
+}
+
+void SessionWidget::closeSession()
+{
+ clearError();
+ session->close();
+ updateSession();
+}
+
+void SessionWidget::stopSession()
+{
+ clearError();
+ session->stop();
+ updateSession();
+}
+
+void SessionWidget::updateSessionState(QNetworkSession::State state)
+{
+ QString s = tr("%1 (%2)");
+
+ switch (state) {
+ case QNetworkSession::Invalid:
+ s = s.arg(tr("Invalid"));
+ break;
+ case QNetworkSession::NotAvailable:
+ s = s.arg(tr("Not Available"));
+ break;
+ case QNetworkSession::Connecting:
+ s = s.arg(tr("Connecting"));
+ break;
+ case QNetworkSession::Connected:
+ s = s.arg(tr("Connected"));
+ break;
+ case QNetworkSession::Closing:
+ s = s.arg(tr("Closing"));
+ break;
+ case QNetworkSession::Disconnected:
+ s = s.arg(tr("Disconnected"));
+ break;
+ case QNetworkSession::Roaming:
+ s = s.arg(tr("Roaming"));
+ break;
+ default:
+ s = s.arg(tr("Unknown"));
+ }
+
+ if (session->isOpen())
+ s = s.arg(tr("Open"));
+ else
+ s = s.arg(tr("Closed"));
+
+ sessionState->setText(s);
+}
+
+void SessionWidget::updateSessionError(QNetworkSession::SessionError error)
+{
+ lastError->setText(QString::number(error));
+ errorString->setText(session->errorString());
+}
+
+void SessionWidget::clearError()
+{
+ lastError->clear();
+ errorString->clear();
+}
diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h
new file mode 100644
index 0000000000..4b14993082
--- /dev/null
+++ b/examples/network/bearermonitor/sessionwidget.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SESSIONWIDGET_H
+#define SESSIONWIDGET_H
+
+#include <qnetworksession.h>
+
+#ifdef MAEMO_UI
+#include "ui_sessionwidget_maemo.h"
+#else
+#include "ui_sessionwidget.h"
+#endif
+
+QT_USE_NAMESPACE
+
+class SessionWidget : public QWidget, public Ui_SessionWidget
+{
+ Q_OBJECT
+
+public:
+ explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0);
+ ~SessionWidget();
+
+ void timerEvent(QTimerEvent *);
+
+private:
+ void updateSessionState(QNetworkSession::State state);
+ void clearError();
+
+private Q_SLOTS:
+ void openSession();
+ void openSyncSession();
+ void closeSession();
+ void stopSession();
+ void updateSession();
+ void updateSessionError(QNetworkSession::SessionError error);
+#ifdef MAEMO_UI
+ void deleteSession();
+#endif
+
+
+private:
+ QNetworkSession *session;
+ int statsTimer;
+};
+
+#endif
+
diff --git a/examples/network/bearermonitor/sessionwidget.ui b/examples/network/bearermonitor/sessionwidget.ui
new file mode 100644
index 0000000000..4199109ce3
--- /dev/null
+++ b/examples/network/bearermonitor/sessionwidget.ui
@@ -0,0 +1,307 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SessionWidget</class>
+ <widget class="QWidget" name="SessionWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>340</width>
+ <height>276</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Session Details</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="sessionIdLayout">
+ <item>
+ <widget class="QLabel" name="sessionIdLabel">
+ <property name="text">
+ <string>Session ID:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="sessionId">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="sessionStateLayout">
+ <item>
+ <widget class="QLabel" name="sessionStateLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Session State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="sessionState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Invalid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationLayout">
+ <item>
+ <widget class="QLabel" name="configurationLabel">
+ <property name="text">
+ <string>Configuration:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configuration">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="bearerLayout">
+ <item>
+ <widget class="QLabel" name="bearerLabel">
+ <property name="text">
+ <string>Bearer:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="bearer">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="interfaceNameLayout">
+ <item>
+ <widget class="QLabel" name="interfaceNameLabel">
+ <property name="text">
+ <string>Interface Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="interfaceName">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="interfaceGuidLayout">
+ <item>
+ <widget class="QLabel" name="interfaceGuidLabel">
+ <property name="text">
+ <string>Interface GUID:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="interfaceGuid">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="lastErrorLayout">
+ <item>
+ <widget class="QLabel" name="lastErrorLabel">
+ <property name="text">
+ <string>Last Error:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="lastError">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout">
+ <item>
+ <widget class="QLabel" name="errorStringLabel">
+ <property name="text">
+ <string>Error String:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="errorString">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="rxData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="txData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Active Time:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="activeTime">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>0 seconds</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="openSessionButton">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="openSyncSessionButton">
+ <property name="text">
+ <string>Blocking Open</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QPushButton" name="closeSessionButton">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stopSessionButton">
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/bearermonitor/sessionwidget_maemo.ui b/examples/network/bearermonitor/sessionwidget_maemo.ui
new file mode 100644
index 0000000000..8867509d01
--- /dev/null
+++ b/examples/network/bearermonitor/sessionwidget_maemo.ui
@@ -0,0 +1,310 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SessionWidget</class>
+ <widget class="QWidget" name="SessionWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>497</width>
+ <height>615</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Session Details</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="sessionIdLayout">
+ <item>
+ <widget class="QLabel" name="sessionIdLabel">
+ <property name="text">
+ <string>Session ID:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="sessionId">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="sessionStateLayout">
+ <item>
+ <widget class="QLabel" name="sessionStateLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Session State:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="sessionState">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Invalid</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="configurationLayout">
+ <item>
+ <widget class="QLabel" name="configurationLabel">
+ <property name="text">
+ <string>Configuration:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="configuration">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="bearerLayout">
+ <item>
+ <widget class="QLabel" name="bearerLabel">
+ <property name="text">
+ <string>Bearer:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="bearer">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="interfaceNameLayout">
+ <item>
+ <widget class="QLabel" name="interfaceNameLabel">
+ <property name="text">
+ <string>Interface Name:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="interfaceName">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="interfaceGuidLayout">
+ <item>
+ <widget class="QLabel" name="interfaceGuidLabel">
+ <property name="text">
+ <string>Interface GUID:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="interfaceGuid">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="lastErrorLayout">
+ <item>
+ <widget class="QLabel" name="lastErrorLabel">
+ <property name="text">
+ <string>Last Error:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="lastError">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout">
+ <item>
+ <widget class="QLabel" name="errorStringLabel">
+ <property name="text">
+ <string>Error String</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="errorString">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout_2">
+ <item>
+ <widget class="QLabel" name="rxData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="txData">
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="errorStringLayout_3">
+ <item>
+ <widget class="QLabel" name="errorStringLabel_2">
+ <property name="text">
+ <string>Active Time:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="activeTime">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>0 seconds</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QPushButton" name="openSessionButton">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeSessionButton">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="openSyncSessionButton">
+ <property name="text">
+ <string>Blocking Open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="stopSessionButton">
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteSessionButton">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/blockingfortuneclient/blockingclient.cpp b/examples/network/blockingfortuneclient/blockingclient.cpp
new file mode 100644
index 0000000000..f5def3d927
--- /dev/null
+++ b/examples/network/blockingfortuneclient/blockingclient.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "blockingclient.h"
+
+BlockingClient::BlockingClient(QWidget *parent)
+ : QDialog(parent)
+{
+ hostLabel = new QLabel(tr("&Server name:"));
+ portLabel = new QLabel(tr("S&erver port:"));
+
+ // find out which IP to connect to
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address()) {
+ ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+
+ hostLineEdit = new QLineEdit(ipAddress);
+ portLineEdit = new QLineEdit;
+ portLineEdit->setValidator(new QIntValidator(1, 65535, this));
+
+ hostLabel->setBuddy(hostLineEdit);
+ portLabel->setBuddy(portLineEdit);
+
+ statusLabel = new QLabel(tr("This examples requires that you run the "
+ "Fortune Server example as well."));
+
+ getFortuneButton = new QPushButton(tr("Get Fortune"));
+ getFortuneButton->setDefault(true);
+ getFortuneButton->setEnabled(false);
+
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ connect(hostLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(portLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(getFortuneButton, SIGNAL(clicked()),
+ this, SLOT(requestNewFortune()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+//! [0]
+ connect(&thread, SIGNAL(newFortune(QString)),
+ this, SLOT(showFortune(QString)));
+//! [0] //! [1]
+ connect(&thread, SIGNAL(error(int,QString)),
+ this, SLOT(displayError(int,QString)));
+//! [1]
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(hostLabel, 0, 0);
+ mainLayout->addWidget(hostLineEdit, 0, 1);
+ mainLayout->addWidget(portLabel, 1, 0);
+ mainLayout->addWidget(portLineEdit, 1, 1);
+ mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Blocking Fortune Client"));
+ portLineEdit->setFocus();
+}
+
+//! [2]
+void BlockingClient::requestNewFortune()
+{
+ getFortuneButton->setEnabled(false);
+ thread.requestNewFortune(hostLineEdit->text(),
+ portLineEdit->text().toInt());
+}
+//! [2]
+
+//! [3]
+void BlockingClient::showFortune(const QString &nextFortune)
+{
+ if (nextFortune == currentFortune) {
+ requestNewFortune();
+ return;
+ }
+//! [3]
+
+//! [4]
+ currentFortune = nextFortune;
+ statusLabel->setText(currentFortune);
+ getFortuneButton->setEnabled(true);
+}
+//! [4]
+
+void BlockingClient::displayError(int socketError, const QString &message)
+{
+ switch (socketError) {
+ case QAbstractSocket::HostNotFoundError:
+ QMessageBox::information(this, tr("Blocking Fortune Client"),
+ tr("The host was not found. Please check the "
+ "host and port settings."));
+ break;
+ case QAbstractSocket::ConnectionRefusedError:
+ QMessageBox::information(this, tr("Blocking Fortune Client"),
+ tr("The connection was refused by the peer. "
+ "Make sure the fortune server is running, "
+ "and check that the host name and port "
+ "settings are correct."));
+ break;
+ default:
+ QMessageBox::information(this, tr("Blocking Fortune Client"),
+ tr("The following error occurred: %1.")
+ .arg(message));
+ }
+
+ getFortuneButton->setEnabled(true);
+}
+
+void BlockingClient::enableGetFortuneButton()
+{
+ getFortuneButton->setEnabled(!hostLineEdit->text().isEmpty()
+ && !portLineEdit->text().isEmpty());
+}
diff --git a/examples/network/blockingfortuneclient/blockingclient.h b/examples/network/blockingfortuneclient/blockingclient.h
new file mode 100644
index 0000000000..8b76fa6596
--- /dev/null
+++ b/examples/network/blockingfortuneclient/blockingclient.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLOCKINGCLIENT_H
+#define BLOCKINGCLIENT_H
+
+#include <QDialog>
+
+#include "fortunethread.h"
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+//! [0]
+class BlockingClient : public QDialog
+{
+ Q_OBJECT
+
+public:
+ BlockingClient(QWidget *parent = 0);
+
+private slots:
+ void requestNewFortune();
+ void showFortune(const QString &fortune);
+ void displayError(int socketError, const QString &message);
+ void enableGetFortuneButton();
+
+private:
+ QLabel *hostLabel;
+ QLabel *portLabel;
+ QLineEdit *hostLineEdit;
+ QLineEdit *portLineEdit;
+ QLabel *statusLabel;
+ QPushButton *getFortuneButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ FortuneThread thread;
+ QString currentFortune;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/blockingfortuneclient/blockingfortuneclient.pro b/examples/network/blockingfortuneclient/blockingfortuneclient.pro
new file mode 100644
index 0000000000..38832acbe5
--- /dev/null
+++ b/examples/network/blockingfortuneclient/blockingfortuneclient.pro
@@ -0,0 +1,14 @@
+HEADERS = blockingclient.h \
+ fortunethread.h
+SOURCES = blockingclient.cpp \
+ main.cpp \
+ fortunethread.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/blockingfortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS blockingfortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/blockingfortuneclient
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/blockingfortuneclient/fortunethread.cpp b/examples/network/blockingfortuneclient/fortunethread.cpp
new file mode 100644
index 0000000000..ad3688bc5a
--- /dev/null
+++ b/examples/network/blockingfortuneclient/fortunethread.cpp
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtNetwork>
+
+#include "fortunethread.h"
+
+FortuneThread::FortuneThread(QObject *parent)
+ : QThread(parent), quit(false)
+{
+}
+
+//! [0]
+FortuneThread::~FortuneThread()
+{
+ mutex.lock();
+ quit = true;
+ cond.wakeOne();
+ mutex.unlock();
+ wait();
+}
+//! [0]
+
+//! [1] //! [2]
+void FortuneThread::requestNewFortune(const QString &hostName, quint16 port)
+{
+//! [1]
+ QMutexLocker locker(&mutex);
+ this->hostName = hostName;
+ this->port = port;
+//! [3]
+ if (!isRunning())
+ start();
+ else
+ cond.wakeOne();
+}
+//! [2] //! [3]
+
+//! [4]
+void FortuneThread::run()
+{
+ mutex.lock();
+//! [4] //! [5]
+ QString serverName = hostName;
+ quint16 serverPort = port;
+ mutex.unlock();
+//! [5]
+
+//! [6]
+ while (!quit) {
+//! [7]
+ const int Timeout = 5 * 1000;
+
+ QTcpSocket socket;
+ socket.connectToHost(serverName, serverPort);
+//! [6] //! [8]
+
+ if (!socket.waitForConnected(Timeout)) {
+ emit error(socket.error(), socket.errorString());
+ return;
+ }
+//! [8] //! [9]
+
+ while (socket.bytesAvailable() < (int)sizeof(quint16)) {
+ if (!socket.waitForReadyRead(Timeout)) {
+ emit error(socket.error(), socket.errorString());
+ return;
+ }
+//! [9] //! [10]
+ }
+//! [10] //! [11]
+
+ quint16 blockSize;
+ QDataStream in(&socket);
+ in.setVersion(QDataStream::Qt_4_0);
+ in >> blockSize;
+//! [11] //! [12]
+
+ while (socket.bytesAvailable() < blockSize) {
+ if (!socket.waitForReadyRead(Timeout)) {
+ emit error(socket.error(), socket.errorString());
+ return;
+ }
+//! [12] //! [13]
+ }
+//! [13] //! [14]
+
+ mutex.lock();
+ QString fortune;
+ in >> fortune;
+ emit newFortune(fortune);
+//! [7] //! [14] //! [15]
+
+ cond.wait(&mutex);
+ serverName = hostName;
+ serverPort = port;
+ mutex.unlock();
+ }
+//! [15]
+}
diff --git a/examples/network/blockingfortuneclient/fortunethread.h b/examples/network/blockingfortuneclient/fortunethread.h
new file mode 100644
index 0000000000..3f4ca25c86
--- /dev/null
+++ b/examples/network/blockingfortuneclient/fortunethread.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FORTUNETHREAD_H
+#define FORTUNETHREAD_H
+
+#include <QThread>
+#include <QMutex>
+#include <QWaitCondition>
+
+//! [0]
+class FortuneThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ FortuneThread(QObject *parent = 0);
+ ~FortuneThread();
+
+ void requestNewFortune(const QString &hostName, quint16 port);
+ void run();
+
+signals:
+ void newFortune(const QString &fortune);
+ void error(int socketError, const QString &message);
+
+private:
+ QString hostName;
+ quint16 port;
+ QMutex mutex;
+ QWaitCondition cond;
+ bool quit;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/blockingfortuneclient/main.cpp b/examples/network/blockingfortuneclient/main.cpp
new file mode 100644
index 0000000000..d1ff1659af
--- /dev/null
+++ b/examples/network/blockingfortuneclient/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "blockingclient.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ BlockingClient client;
+ client.show();
+ return client.exec();
+}
diff --git a/examples/network/broadcastreceiver/broadcastreceiver.pro b/examples/network/broadcastreceiver/broadcastreceiver.pro
new file mode 100644
index 0000000000..602ad373c4
--- /dev/null
+++ b/examples/network/broadcastreceiver/broadcastreceiver.pro
@@ -0,0 +1,12 @@
+HEADERS = receiver.h
+SOURCES = receiver.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/broadcastreceiver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS broadcastreceiver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/broadcastreceiver
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/broadcastreceiver/main.cpp b/examples/network/broadcastreceiver/main.cpp
new file mode 100644
index 0000000000..041163178d
--- /dev/null
+++ b/examples/network/broadcastreceiver/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "receiver.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Receiver receiver;
+ receiver.show();
+ return receiver.exec();
+}
diff --git a/examples/network/broadcastreceiver/receiver.cpp b/examples/network/broadcastreceiver/receiver.cpp
new file mode 100644
index 0000000000..bd45a3cb35
--- /dev/null
+++ b/examples/network/broadcastreceiver/receiver.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "receiver.h"
+
+Receiver::Receiver(QWidget *parent)
+ : QDialog(parent)
+{
+ statusLabel = new QLabel(tr("Listening for broadcasted messages"));
+ quitButton = new QPushButton(tr("&Quit"));
+
+//! [0]
+ udpSocket = new QUdpSocket(this);
+ udpSocket->bind(45454, QUdpSocket::ShareAddress);
+//! [0]
+
+//! [1]
+ connect(udpSocket, SIGNAL(readyRead()),
+ this, SLOT(processPendingDatagrams()));
+//! [1]
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Broadcast Receiver"));
+}
+
+void Receiver::processPendingDatagrams()
+{
+//! [2]
+ while (udpSocket->hasPendingDatagrams()) {
+ QByteArray datagram;
+ datagram.resize(udpSocket->pendingDatagramSize());
+ udpSocket->readDatagram(datagram.data(), datagram.size());
+ statusLabel->setText(tr("Received datagram: \"%1\"")
+ .arg(datagram.data()));
+ }
+//! [2]
+}
diff --git a/examples/network/broadcastreceiver/receiver.h b/examples/network/broadcastreceiver/receiver.h
new file mode 100644
index 0000000000..80b35a5571
--- /dev/null
+++ b/examples/network/broadcastreceiver/receiver.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RECEIVER_H
+#define RECEIVER_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QUdpSocket;
+QT_END_NAMESPACE
+
+class Receiver : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Receiver(QWidget *parent = 0);
+
+private slots:
+ void processPendingDatagrams();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ QUdpSocket *udpSocket;
+};
+
+#endif
diff --git a/examples/network/broadcastsender/broadcastsender.pro b/examples/network/broadcastsender/broadcastsender.pro
new file mode 100644
index 0000000000..9a03765bb7
--- /dev/null
+++ b/examples/network/broadcastsender/broadcastsender.pro
@@ -0,0 +1,12 @@
+HEADERS = sender.h
+SOURCES = sender.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/broadcastsender
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS broadcastsender.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/broadcastsender
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/broadcastsender/main.cpp b/examples/network/broadcastsender/main.cpp
new file mode 100644
index 0000000000..56e35c9540
--- /dev/null
+++ b/examples/network/broadcastsender/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "sender.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Sender sender;
+ sender.show();
+ return sender.exec();
+}
diff --git a/examples/network/broadcastsender/sender.cpp b/examples/network/broadcastsender/sender.cpp
new file mode 100644
index 0000000000..d753094637
--- /dev/null
+++ b/examples/network/broadcastsender/sender.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "sender.h"
+
+Sender::Sender(QWidget *parent)
+ : QDialog(parent)
+{
+ statusLabel = new QLabel(tr("Ready to broadcast datagrams on port 45454"));
+
+ startButton = new QPushButton(tr("&Start"));
+ quitButton = new QPushButton(tr("&Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(startButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ timer = new QTimer(this);
+//! [0]
+ udpSocket = new QUdpSocket(this);
+//! [0]
+ messageNo = 1;
+
+ connect(startButton, SIGNAL(clicked()), this, SLOT(startBroadcasting()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Broadcast Sender"));
+}
+
+void Sender::startBroadcasting()
+{
+ startButton->setEnabled(false);
+ timer->start(1000);
+}
+
+void Sender::broadcastDatagram()
+{
+ statusLabel->setText(tr("Now broadcasting datagram %1").arg(messageNo));
+//! [1]
+ QByteArray datagram = "Broadcast message " + QByteArray::number(messageNo);
+ udpSocket->writeDatagram(datagram.data(), datagram.size(),
+ QHostAddress::Broadcast, 45454);
+//! [1]
+ ++messageNo;
+}
diff --git a/examples/network/broadcastsender/sender.h b/examples/network/broadcastsender/sender.h
new file mode 100644
index 0000000000..d592051efd
--- /dev/null
+++ b/examples/network/broadcastsender/sender.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SENDER_H
+#define SENDER_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QPushButton;
+class QTimer;
+class QUdpSocket;
+QT_END_NAMESPACE
+
+class Sender : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Sender(QWidget *parent = 0);
+
+private slots:
+ void startBroadcasting();
+ void broadcastDatagram();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *startButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+ QUdpSocket *udpSocket;
+ QTimer *timer;
+ int messageNo;
+};
+
+#endif
diff --git a/examples/network/download/download.pro b/examples/network/download/download.pro
new file mode 100644
index 0000000000..780d61fae0
--- /dev/null
+++ b/examples/network/download/download.pro
@@ -0,0 +1,21 @@
+######################################################################
+# Automatically generated by qmake (2.01a) fr. nov. 16 13:18:20 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT = core network
+CONFIG += console
+
+# Input
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/download
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/download
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/download/main.cpp b/examples/network/download/main.cpp
new file mode 100644
index 0000000000..1b7e54ba11
--- /dev/null
+++ b/examples/network/download/main.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QFile>
+#include <QFileInfo>
+#include <QList>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QSslError>
+#include <QStringList>
+#include <QTimer>
+#include <QUrl>
+
+#include <stdio.h>
+
+QT_BEGIN_NAMESPACE
+class QSslError;
+QT_END_NAMESPACE
+
+QT_USE_NAMESPACE
+
+class DownloadManager: public QObject
+{
+ Q_OBJECT
+ QNetworkAccessManager manager;
+ QList<QNetworkReply *> currentDownloads;
+
+public:
+ DownloadManager();
+ void doDownload(const QUrl &url);
+ QString saveFileName(const QUrl &url);
+ bool saveToDisk(const QString &filename, QIODevice *data);
+
+public slots:
+ void execute();
+ void downloadFinished(QNetworkReply *reply);
+ void sslErrors(const QList<QSslError> &errors);
+};
+
+DownloadManager::DownloadManager()
+{
+ connect(&manager, SIGNAL(finished(QNetworkReply*)),
+ SLOT(downloadFinished(QNetworkReply*)));
+}
+
+void DownloadManager::doDownload(const QUrl &url)
+{
+ QNetworkRequest request(url);
+ QNetworkReply *reply = manager.get(request);
+ connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(sslErrors(QList<QSslError>)));
+
+ currentDownloads.append(reply);
+}
+
+QString DownloadManager::saveFileName(const QUrl &url)
+{
+ QString path = url.path();
+ QString basename = QFileInfo(path).fileName();
+
+ if (basename.isEmpty())
+ basename = "download";
+
+ if (QFile::exists(basename)) {
+ // already exists, don't overwrite
+ int i = 0;
+ basename += '.';
+ while (QFile::exists(basename + QString::number(i)))
+ ++i;
+
+ basename += QString::number(i);
+ }
+
+ return basename;
+}
+
+bool DownloadManager::saveToDisk(const QString &filename, QIODevice *data)
+{
+ QFile file(filename);
+ if (!file.open(QIODevice::WriteOnly)) {
+ fprintf(stderr, "Could not open %s for writing: %s\n",
+ qPrintable(filename),
+ qPrintable(file.errorString()));
+ return false;
+ }
+
+ file.write(data->readAll());
+ file.close();
+
+ return true;
+}
+
+void DownloadManager::execute()
+{
+ QStringList args = QCoreApplication::instance()->arguments();
+ args.takeFirst(); // skip the first argument, which is the program's name
+ if (args.isEmpty()) {
+ printf("Qt Download example - downloads all URLs in parallel\n"
+ "Usage: download url1 [url2... urlN]\n"
+ "\n"
+ "Downloads the URLs passed in the command-line to the local directory\n"
+ "If the target file already exists, a .0, .1, .2, etc. is appended to\n"
+ "differentiate.\n");
+ QCoreApplication::instance()->quit();
+ return;
+ }
+
+ foreach (QString arg, args) {
+ QUrl url = QUrl::fromEncoded(arg.toLocal8Bit());
+ doDownload(url);
+ }
+}
+
+void DownloadManager::sslErrors(const QList<QSslError> &sslErrors)
+{
+#ifndef QT_NO_OPENSSL
+ foreach (const QSslError &error, sslErrors)
+ fprintf(stderr, "SSL error: %s\n", qPrintable(error.errorString()));
+#endif
+}
+
+void DownloadManager::downloadFinished(QNetworkReply *reply)
+{
+ QUrl url = reply->url();
+ if (reply->error()) {
+ fprintf(stderr, "Download of %s failed: %s\n",
+ url.toEncoded().constData(),
+ qPrintable(reply->errorString()));
+ } else {
+ QString filename = saveFileName(url);
+ if (saveToDisk(filename, reply))
+ printf("Download of %s succeeded (saved to %s)\n",
+ url.toEncoded().constData(), qPrintable(filename));
+ }
+
+ currentDownloads.removeAll(reply);
+ reply->deleteLater();
+
+ if (currentDownloads.isEmpty())
+ // all downloads finished
+ QCoreApplication::instance()->quit();
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ DownloadManager manager;
+ QTimer::singleShot(0, &manager, SLOT(execute()));
+
+ app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/network/downloadmanager/downloadmanager.cpp b/examples/network/downloadmanager/downloadmanager.cpp
new file mode 100644
index 0000000000..d58ffdf99d
--- /dev/null
+++ b/examples/network/downloadmanager/downloadmanager.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "downloadmanager.h"
+
+#include <QFileInfo>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QString>
+#include <QStringList>
+#include <QTimer>
+#include <stdio.h>
+
+DownloadManager::DownloadManager(QObject *parent)
+ : QObject(parent), downloadedCount(0), totalCount(0)
+{
+}
+
+void DownloadManager::append(const QStringList &urlList)
+{
+ foreach (QString url, urlList)
+ append(QUrl::fromEncoded(url.toLocal8Bit()));
+
+ if (downloadQueue.isEmpty())
+ QTimer::singleShot(0, this, SIGNAL(finished()));
+}
+
+void DownloadManager::append(const QUrl &url)
+{
+ if (downloadQueue.isEmpty())
+ QTimer::singleShot(0, this, SLOT(startNextDownload()));
+
+ downloadQueue.enqueue(url);
+ ++totalCount;
+}
+
+QString DownloadManager::saveFileName(const QUrl &url)
+{
+ QString path = url.path();
+ QString basename = QFileInfo(path).fileName();
+
+ if (basename.isEmpty())
+ basename = "download";
+
+ if (QFile::exists(basename)) {
+ // already exists, don't overwrite
+ int i = 0;
+ basename += '.';
+ while (QFile::exists(basename + QString::number(i)))
+ ++i;
+
+ basename += QString::number(i);
+ }
+
+ return basename;
+}
+
+void DownloadManager::startNextDownload()
+{
+ if (downloadQueue.isEmpty()) {
+ printf("%d/%d files downloaded successfully\n", downloadedCount, totalCount);
+ emit finished();
+ return;
+ }
+
+ QUrl url = downloadQueue.dequeue();
+
+ QString filename = saveFileName(url);
+ output.setFileName(filename);
+ if (!output.open(QIODevice::WriteOnly)) {
+ fprintf(stderr, "Problem opening save file '%s' for download '%s': %s\n",
+ qPrintable(filename), url.toEncoded().constData(),
+ qPrintable(output.errorString()));
+
+ startNextDownload();
+ return; // skip this download
+ }
+
+ QNetworkRequest request(url);
+ currentDownload = manager.get(request);
+ connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
+ SLOT(downloadProgress(qint64,qint64)));
+ connect(currentDownload, SIGNAL(finished()),
+ SLOT(downloadFinished()));
+ connect(currentDownload, SIGNAL(readyRead()),
+ SLOT(downloadReadyRead()));
+
+ // prepare the output
+ printf("Downloading %s...\n", url.toEncoded().constData());
+ downloadTime.start();
+}
+
+void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
+{
+ progressBar.setStatus(bytesReceived, bytesTotal);
+
+ // calculate the download speed
+ double speed = bytesReceived * 1000.0 / downloadTime.elapsed();
+ QString unit;
+ if (speed < 1024) {
+ unit = "bytes/sec";
+ } else if (speed < 1024*1024) {
+ speed /= 1024;
+ unit = "kB/s";
+ } else {
+ speed /= 1024*1024;
+ unit = "MB/s";
+ }
+
+ progressBar.setMessage(QString::fromLatin1("%1 %2")
+ .arg(speed, 3, 'f', 1).arg(unit));
+ progressBar.update();
+}
+
+void DownloadManager::downloadFinished()
+{
+ progressBar.clear();
+ output.close();
+
+ if (currentDownload->error()) {
+ // download failed
+ fprintf(stderr, "Failed: %s\n", qPrintable(currentDownload->errorString()));
+ } else {
+ printf("Succeeded.\n");
+ ++downloadedCount;
+ }
+
+ currentDownload->deleteLater();
+ startNextDownload();
+}
+
+void DownloadManager::downloadReadyRead()
+{
+ output.write(currentDownload->readAll());
+}
diff --git a/examples/network/downloadmanager/downloadmanager.h b/examples/network/downloadmanager/downloadmanager.h
new file mode 100644
index 0000000000..98e72b0f4c
--- /dev/null
+++ b/examples/network/downloadmanager/downloadmanager.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DOWNLOADMANAGER_H
+#define DOWNLOADMANAGER_H
+
+#include <QFile>
+#include <QObject>
+#include <QQueue>
+#include <QTime>
+#include <QUrl>
+#include <QNetworkAccessManager>
+
+#include "textprogressbar.h"
+
+class DownloadManager: public QObject
+{
+ Q_OBJECT
+public:
+ DownloadManager(QObject *parent = 0);
+
+ void append(const QUrl &url);
+ void append(const QStringList &urlList);
+ QString saveFileName(const QUrl &url);
+
+signals:
+ void finished();
+
+private slots:
+ void startNextDownload();
+ void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+ void downloadFinished();
+ void downloadReadyRead();
+
+private:
+ QNetworkAccessManager manager;
+ QQueue<QUrl> downloadQueue;
+ QNetworkReply *currentDownload;
+ QFile output;
+ QTime downloadTime;
+ TextProgressBar progressBar;
+
+ int downloadedCount;
+ int totalCount;
+};
+
+#endif
diff --git a/examples/network/downloadmanager/downloadmanager.pro b/examples/network/downloadmanager/downloadmanager.pro
new file mode 100644
index 0000000000..5c618cdfbf
--- /dev/null
+++ b/examples/network/downloadmanager/downloadmanager.pro
@@ -0,0 +1,22 @@
+######################################################################
+# Automatically generated by qmake (2.01a) fr. nov. 16 14:11:36 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+QT = core network
+CONFIG += console
+
+# Input
+HEADERS += downloadmanager.h textprogressbar.h
+SOURCES += downloadmanager.cpp main.cpp textprogressbar.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/downloadmanager
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/downloadmanager
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/downloadmanager/main.cpp b/examples/network/downloadmanager/main.cpp
new file mode 100644
index 0000000000..ed738472f7
--- /dev/null
+++ b/examples/network/downloadmanager/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QStringList>
+#include "downloadmanager.h"
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+ QStringList arguments = app.arguments();
+ arguments.takeFirst(); // remove the first argument, which is the program's name
+
+ if (arguments.isEmpty()) {
+ printf("Qt Download example\n"
+ "Usage: downloadmanager url1 [url2... urlN]\n"
+ "\n"
+ "Downloads the URLs passed in the command-line to the local directory\n"
+ "If the target file already exists, a .0, .1, .2, etc. is appended to\n"
+ "differentiate.\n");
+ return 0;
+ }
+
+ DownloadManager manager;
+ manager.append(arguments);
+
+ QObject::connect(&manager, SIGNAL(finished()), &app, SLOT(quit()));
+ app.exec();
+}
diff --git a/examples/network/downloadmanager/textprogressbar.cpp b/examples/network/downloadmanager/textprogressbar.cpp
new file mode 100644
index 0000000000..0303752b4b
--- /dev/null
+++ b/examples/network/downloadmanager/textprogressbar.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textprogressbar.h"
+#include <QByteArray>
+#include <stdio.h>
+
+TextProgressBar::TextProgressBar()
+ : value(0), maximum(-1), iteration(0)
+{
+}
+
+void TextProgressBar::clear()
+{
+ printf("\n");
+ fflush(stdout);
+
+ iteration = 0;
+ value = 0;
+ maximum = -1;
+}
+
+void TextProgressBar::update()
+{
+ ++iteration;
+
+ if (maximum > 0) {
+ // we know the maximum
+ // draw a progress bar
+ int percent = value * 100 / maximum;
+ int hashes = percent / 2;
+
+ QByteArray progressbar(hashes, '#');
+ if (percent % 2)
+ progressbar += '>';
+
+ printf("\r[%-50s] %3d%% %s ",
+ progressbar.constData(),
+ percent,
+ qPrintable(message));
+ } else {
+ // we don't know the maximum, so we can't draw a progress bar
+ int center = (iteration % 48) + 1; // 50 spaces, minus 2
+ QByteArray before(qMax(center - 2, 0), ' ');
+ QByteArray after(qMin(center + 2, 50), ' ');
+
+ printf("\r[%s###%s] %s ",
+ before.constData(), after.constData(), qPrintable(message));
+ }
+}
+
+void TextProgressBar::setMessage(const QString &m)
+{
+ message = m;
+}
+
+void TextProgressBar::setStatus(qint64 val, qint64 max)
+{
+ value = val;
+ maximum = max;
+}
diff --git a/examples/network/downloadmanager/textprogressbar.h b/examples/network/downloadmanager/textprogressbar.h
new file mode 100644
index 0000000000..3d2be5565a
--- /dev/null
+++ b/examples/network/downloadmanager/textprogressbar.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTPROGRESSBAR_H
+#define TEXTPROGRESSBAR_H
+
+#include <QString>
+
+class TextProgressBar
+{
+public:
+ TextProgressBar();
+
+ void clear();
+ void update();
+ void setMessage(const QString &message);
+ void setStatus(qint64 value, qint64 maximum);
+
+private:
+ QString message;
+ qint64 value;
+ qint64 maximum;
+ int iteration;
+};
+
+#endif
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
new file mode 100644
index 0000000000..9eab1c2371
--- /dev/null
+++ b/examples/network/fortuneclient/client.cpp
@@ -0,0 +1,252 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "client.h"
+
+//! [0]
+Client::Client(QWidget *parent)
+: QDialog(parent), networkSession(0)
+{
+//! [0]
+ hostLabel = new QLabel(tr("&Server name:"));
+ portLabel = new QLabel(tr("S&erver port:"));
+
+ // find out which IP to connect to
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address()) {
+ ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+
+ hostLineEdit = new QLineEdit(ipAddress);
+ portLineEdit = new QLineEdit;
+ portLineEdit->setValidator(new QIntValidator(1, 65535, this));
+
+ hostLabel->setBuddy(hostLineEdit);
+ portLabel->setBuddy(portLineEdit);
+
+ statusLabel = new QLabel(tr("This examples requires that you run the "
+ "Fortune Server example as well."));
+
+ getFortuneButton = new QPushButton(tr("Get Fortune"));
+ getFortuneButton->setDefault(true);
+ getFortuneButton->setEnabled(false);
+
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(getFortuneButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+//! [1]
+ tcpSocket = new QTcpSocket(this);
+//! [1]
+
+ connect(hostLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(portLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableGetFortuneButton()));
+ connect(getFortuneButton, SIGNAL(clicked()),
+ this, SLOT(requestNewFortune()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+//! [2] //! [3]
+ connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
+//! [2] //! [4]
+ connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
+//! [3]
+ this, SLOT(displayError(QAbstractSocket::SocketError)));
+//! [4]
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(hostLabel, 0, 0);
+ mainLayout->addWidget(hostLineEdit, 0, 1);
+ mainLayout->addWidget(portLabel, 1, 0);
+ mainLayout->addWidget(portLineEdit, 1, 1);
+ mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Fortune Client"));
+ portLineEdit->setFocus();
+
+ QNetworkConfigurationManager manager;
+ if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
+ // Get saved network configuration
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
+ settings.endGroup();
+
+ // If the saved network configuration is not currently discovered use the system default
+ QNetworkConfiguration config = manager.configurationFromIdentifier(id);
+ if ((config.state() & QNetworkConfiguration::Discovered) !=
+ QNetworkConfiguration::Discovered) {
+ config = manager.defaultConfiguration();
+ }
+
+ networkSession = new QNetworkSession(config, this);
+ connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
+
+ getFortuneButton->setEnabled(false);
+ statusLabel->setText(tr("Opening network session."));
+ networkSession->open();
+ }
+//! [5]
+}
+//! [5]
+
+//! [6]
+void Client::requestNewFortune()
+{
+ getFortuneButton->setEnabled(false);
+ blockSize = 0;
+ tcpSocket->abort();
+//! [7]
+ tcpSocket->connectToHost(hostLineEdit->text(),
+ portLineEdit->text().toInt());
+//! [7]
+}
+//! [6]
+
+//! [8]
+void Client::readFortune()
+{
+//! [9]
+ QDataStream in(tcpSocket);
+ in.setVersion(QDataStream::Qt_4_0);
+
+ if (blockSize == 0) {
+ if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
+ return;
+//! [8]
+
+//! [10]
+ in >> blockSize;
+ }
+
+ if (tcpSocket->bytesAvailable() < blockSize)
+ return;
+//! [10] //! [11]
+
+ QString nextFortune;
+ in >> nextFortune;
+
+ if (nextFortune == currentFortune) {
+ QTimer::singleShot(0, this, SLOT(requestNewFortune()));
+ return;
+ }
+//! [11]
+
+//! [12]
+ currentFortune = nextFortune;
+//! [9]
+ statusLabel->setText(currentFortune);
+ getFortuneButton->setEnabled(true);
+}
+//! [12]
+
+//! [13]
+void Client::displayError(QAbstractSocket::SocketError socketError)
+{
+ switch (socketError) {
+ case QAbstractSocket::RemoteHostClosedError:
+ break;
+ case QAbstractSocket::HostNotFoundError:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The host was not found. Please check the "
+ "host name and port settings."));
+ break;
+ case QAbstractSocket::ConnectionRefusedError:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The connection was refused by the peer. "
+ "Make sure the fortune server is running, "
+ "and check that the host name and port "
+ "settings are correct."));
+ break;
+ default:
+ QMessageBox::information(this, tr("Fortune Client"),
+ tr("The following error occurred: %1.")
+ .arg(tcpSocket->errorString()));
+ }
+
+ getFortuneButton->setEnabled(true);
+}
+//! [13]
+
+void Client::enableGetFortuneButton()
+{
+ getFortuneButton->setEnabled((!networkSession || networkSession->isOpen()) &&
+ !hostLineEdit->text().isEmpty() &&
+ !portLineEdit->text().isEmpty());
+
+}
+
+void Client::sessionOpened()
+{
+ // Save the used configuration
+ QNetworkConfiguration config = networkSession->configuration();
+ QString id;
+ if (config.type() == QNetworkConfiguration::UserChoice)
+ id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
+ else
+ id = config.identifier();
+
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
+ settings.endGroup();
+
+ statusLabel->setText(tr("This examples requires that you run the "
+ "Fortune Server example as well."));
+
+ enableGetFortuneButton();
+}
+
diff --git a/examples/network/fortuneclient/client.h b/examples/network/fortuneclient/client.h
new file mode 100644
index 0000000000..f4a76c4dc2
--- /dev/null
+++ b/examples/network/fortuneclient/client.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <QDialog>
+#include <QTcpSocket>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTcpSocket;
+class QNetworkSession;
+QT_END_NAMESPACE
+
+//! [0]
+class Client : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Client(QWidget *parent = 0);
+
+private slots:
+ void requestNewFortune();
+ void readFortune();
+ void displayError(QAbstractSocket::SocketError socketError);
+ void enableGetFortuneButton();
+ void sessionOpened();
+
+private:
+ QLabel *hostLabel;
+ QLabel *portLabel;
+ QLineEdit *hostLineEdit;
+ QLineEdit *portLineEdit;
+ QLabel *statusLabel;
+ QPushButton *getFortuneButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QTcpSocket *tcpSocket;
+ QString currentFortune;
+ quint16 blockSize;
+
+ QNetworkSession *networkSession;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/fortuneclient/fortuneclient.pro b/examples/network/fortuneclient/fortuneclient.pro
new file mode 100644
index 0000000000..550ba91bd7
--- /dev/null
+++ b/examples/network/fortuneclient/fortuneclient.pro
@@ -0,0 +1,16 @@
+HEADERS = client.h
+SOURCES = client.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/fortuneclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fortuneclient.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/fortuneclient
+INSTALLS += target sources
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.CAPABILITY = "NetworkServices ReadUserData WriteUserData"
+ TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
+}
diff --git a/examples/network/fortuneclient/main.cpp b/examples/network/fortuneclient/main.cpp
new file mode 100644
index 0000000000..bf3cec187f
--- /dev/null
+++ b/examples/network/fortuneclient/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "client.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Client client;
+#ifdef Q_OS_SYMBIAN
+ // Make application better looking and more usable on small screen
+ client.showMaximized();
+#else
+ client.show();
+#endif
+ return client.exec();
+}
diff --git a/examples/network/fortuneserver/fortuneserver.pro b/examples/network/fortuneserver/fortuneserver.pro
new file mode 100644
index 0000000000..3e95bfe3f9
--- /dev/null
+++ b/examples/network/fortuneserver/fortuneserver.pro
@@ -0,0 +1,17 @@
+HEADERS = server.h
+SOURCES = server.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/fortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/fortuneserver
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000E406
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.CAPABILITY = "NetworkServices ReadUserData"
+ TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
+}
diff --git a/examples/network/fortuneserver/main.cpp b/examples/network/fortuneserver/main.cpp
new file mode 100644
index 0000000000..74f182e8d8
--- /dev/null
+++ b/examples/network/fortuneserver/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QtCore>
+
+#include <stdlib.h>
+
+#include "server.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Server server;
+#ifdef Q_OS_SYMBIAN
+ server.showMaximized();
+#else
+ server.show();
+#endif
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ return server.exec();
+}
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
new file mode 100644
index 0000000000..edb8c9398c
--- /dev/null
+++ b/examples/network/fortuneserver/server.cpp
@@ -0,0 +1,176 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include <stdlib.h>
+
+#include "server.h"
+
+Server::Server(QWidget *parent)
+: QDialog(parent), tcpServer(0), networkSession(0)
+{
+ statusLabel = new QLabel;
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+ QNetworkConfigurationManager manager;
+ if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
+ // Get saved network configuration
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
+ settings.endGroup();
+
+ // If the saved network configuration is not currently discovered use the system default
+ QNetworkConfiguration config = manager.configurationFromIdentifier(id);
+ if ((config.state() & QNetworkConfiguration::Discovered) !=
+ QNetworkConfiguration::Discovered) {
+ config = manager.defaultConfiguration();
+ }
+
+ networkSession = new QNetworkSession(config, this);
+ connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));
+
+ statusLabel->setText(tr("Opening network session."));
+ networkSession->open();
+ } else {
+ sessionOpened();
+ }
+
+ //! [2]
+ fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
+ << tr("You've got to think about tomorrow.")
+ << tr("You will be surprised by a loud noise.")
+ << tr("You will feel hungry again in another hour.")
+ << tr("You might have mail.")
+ << tr("You cannot kill time without injuring eternity.")
+ << tr("Computers are not intelligent. They only think they are.");
+ //! [2]
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ //! [3]
+ connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune()));
+ //! [3]
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Fortune Server"));
+}
+
+void Server::sessionOpened()
+{
+ // Save the used configuration
+ if (networkSession) {
+ QNetworkConfiguration config = networkSession->configuration();
+ QString id;
+ if (config.type() == QNetworkConfiguration::UserChoice)
+ id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
+ else
+ id = config.identifier();
+
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
+ settings.endGroup();
+ }
+
+//! [0] //! [1]
+ tcpServer = new QTcpServer(this);
+ if (!tcpServer->listen()) {
+ QMessageBox::critical(this, tr("Fortune Server"),
+ tr("Unable to start the server: %1.")
+ .arg(tcpServer->errorString()));
+ close();
+ return;
+ }
+//! [0]
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address()) {
+ ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+ statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"
+ "Run the Fortune Client example now.")
+ .arg(ipAddress).arg(tcpServer->serverPort()));
+//! [1]
+}
+
+//! [4]
+void Server::sendFortune()
+{
+//! [5]
+ QByteArray block;
+ QDataStream out(&block, QIODevice::WriteOnly);
+ out.setVersion(QDataStream::Qt_4_0);
+//! [4] //! [6]
+ out << (quint16)0;
+ out << fortunes.at(qrand() % fortunes.size());
+ out.device()->seek(0);
+ out << (quint16)(block.size() - sizeof(quint16));
+//! [6] //! [7]
+
+ QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
+ connect(clientConnection, SIGNAL(disconnected()),
+ clientConnection, SLOT(deleteLater()));
+//! [7] //! [8]
+
+ clientConnection->write(block);
+ clientConnection->disconnectFromHost();
+//! [5]
+}
+//! [8]
diff --git a/examples/network/fortuneserver/server.h b/examples/network/fortuneserver/server.h
new file mode 100644
index 0000000000..a04dfa9e71
--- /dev/null
+++ b/examples/network/fortuneserver/server.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SERVER_H
+#define SERVER_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QTcpServer;
+class QNetworkSession;
+QT_END_NAMESPACE
+
+//! [0]
+class Server : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Server(QWidget *parent = 0);
+
+private slots:
+ void sessionOpened();
+ void sendFortune();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ QTcpServer *tcpServer;
+ QStringList fortunes;
+ QNetworkSession *networkSession;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/googlesuggest/googlesuggest.cpp b/examples/network/googlesuggest/googlesuggest.cpp
new file mode 100644
index 0000000000..ed9ff6a20e
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.cpp
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+//! [1]
+#include "googlesuggest.h"
+
+#define GSUGGEST_URL "http://google.com/complete/search?output=toolbar&q=%1"
+//! [1]
+
+//! [2]
+GSuggestCompletion::GSuggestCompletion(QLineEdit *parent): QObject(parent), editor(parent)
+{
+ popup = new QTreeWidget;
+ popup->setWindowFlags(Qt::Popup);
+ popup->setFocusPolicy(Qt::NoFocus);
+ popup->setFocusProxy(parent);
+ popup->setMouseTracking(true);
+
+ popup->setColumnCount(2);
+ popup->setUniformRowHeights(true);
+ popup->setRootIsDecorated(false);
+ popup->setEditTriggers(QTreeWidget::NoEditTriggers);
+ popup->setSelectionBehavior(QTreeWidget::SelectRows);
+ popup->setFrameStyle(QFrame::Box | QFrame::Plain);
+ popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ popup->header()->hide();
+
+ popup->installEventFilter(this);
+
+ connect(popup, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
+ SLOT(doneCompletion()));
+
+ timer = new QTimer(this);
+ timer->setSingleShot(true);
+ timer->setInterval(500);
+ connect(timer, SIGNAL(timeout()), SLOT(autoSuggest()));
+ connect(editor, SIGNAL(textEdited(QString)), timer, SLOT(start()));
+
+ connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(handleNetworkData(QNetworkReply*)));
+
+}
+//! [2]
+
+//! [3]
+GSuggestCompletion::~GSuggestCompletion()
+{
+ delete popup;
+}
+//! [3]
+
+//! [4]
+bool GSuggestCompletion::eventFilter(QObject *obj, QEvent *ev)
+{
+ if (obj != popup)
+ return false;
+
+ if (ev->type() == QEvent::MouseButtonPress) {
+ popup->hide();
+ editor->setFocus();
+ return true;
+ }
+
+ if (ev->type() == QEvent::KeyPress) {
+
+ bool consumed = false;
+ int key = static_cast<QKeyEvent*>(ev)->key();
+ switch (key) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ doneCompletion();
+ consumed = true;
+
+ case Qt::Key_Escape:
+ editor->setFocus();
+ popup->hide();
+ consumed = true;
+
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_Home:
+ case Qt::Key_End:
+ case Qt::Key_PageUp:
+ case Qt::Key_PageDown:
+ break;
+
+ default:
+ editor->setFocus();
+ editor->event(ev);
+ popup->hide();
+ break;
+ }
+
+ return consumed;
+ }
+
+ return false;
+}
+//! [4]
+
+//! [5]
+void GSuggestCompletion::showCompletion(const QStringList &choices, const QStringList &hits)
+{
+
+ if (choices.isEmpty() || choices.count() != hits.count())
+ return;
+
+ const QPalette &pal = editor->palette();
+ QColor color = pal.color(QPalette::Disabled, QPalette::WindowText);
+
+ popup->setUpdatesEnabled(false);
+ popup->clear();
+ for (int i = 0; i < choices.count(); ++i) {
+ QTreeWidgetItem * item;
+ item = new QTreeWidgetItem(popup);
+ item->setText(0, choices[i]);
+ item->setText(1, hits[i]);
+ item->setTextAlignment(1, Qt::AlignRight);
+ item->setTextColor(1, color);
+ }
+ popup->setCurrentItem(popup->topLevelItem(0));
+ popup->resizeColumnToContents(0);
+ popup->resizeColumnToContents(1);
+ popup->adjustSize();
+ popup->setUpdatesEnabled(true);
+
+ int h = popup->sizeHintForRow(0) * qMin(7, choices.count()) + 3;
+ popup->resize(popup->width(), h);
+
+ popup->move(editor->mapToGlobal(QPoint(0, editor->height())));
+ popup->setFocus();
+ popup->show();
+}
+//! [5]
+
+//! [6]
+void GSuggestCompletion::doneCompletion()
+{
+ timer->stop();
+ popup->hide();
+ editor->setFocus();
+ QTreeWidgetItem *item = popup->currentItem();
+ if (item) {
+ editor->setText(item->text(0));
+ QMetaObject::invokeMethod(editor, "returnPressed");
+ }
+}
+//! [6]
+
+//! [7]
+void GSuggestCompletion::autoSuggest()
+{
+ QString str = editor->text();
+ QString url = QString(GSUGGEST_URL).arg(str);
+ networkManager.get(QNetworkRequest(QString(url)));
+}
+//! [7]
+
+//! [8]
+void GSuggestCompletion::preventSuggest()
+{
+ timer->stop();
+}
+//! [8]
+
+//! [9]
+void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply)
+{
+ QUrl url = networkReply->url();
+ if (!networkReply->error()) {
+ QStringList choices;
+ QStringList hits;
+
+ QByteArray response(networkReply->readAll());
+ QXmlStreamReader xml(response);
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.tokenType() == QXmlStreamReader::StartElement)
+ if (xml.name() == "suggestion") {
+ QStringRef str = xml.attributes().value("data");
+ choices << str.toString();
+ }
+ if (xml.tokenType() == QXmlStreamReader::StartElement)
+ if (xml.name() == "num_queries") {
+ QStringRef str = xml.attributes().value("int");
+ hits << str.toString();
+ }
+ }
+
+ showCompletion(choices, hits);
+ }
+
+ networkReply->deleteLater();
+}
+//! [9]
+
diff --git a/examples/network/googlesuggest/googlesuggest.h b/examples/network/googlesuggest/googlesuggest.h
new file mode 100644
index 0000000000..a5d268a126
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GOOGLESUGGEST_H
+#define GOOGLESUGGEST_H
+
+#include <QtGui>
+#include <QtNetwork>
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QNetworkReply;
+class QTimer;
+class QTreeWidget;
+QT_END_NAMESPACE
+
+//! [1]
+class GSuggestCompletion : public QObject
+{
+ Q_OBJECT
+
+public:
+ GSuggestCompletion(QLineEdit *parent = 0);
+ ~GSuggestCompletion();
+ bool eventFilter(QObject *obj, QEvent *ev);
+ void showCompletion(const QStringList &choices, const QStringList &hits);
+
+public slots:
+
+ void doneCompletion();
+ void preventSuggest();
+ void autoSuggest();
+ void handleNetworkData(QNetworkReply *networkReply);
+
+private:
+ QLineEdit *editor;
+ QTreeWidget *popup;
+ QTimer *timer;
+ QNetworkAccessManager networkManager;
+};
+//! [1]
+#endif // GOOGLESUGGEST_H
+
diff --git a/examples/network/googlesuggest/googlesuggest.pro b/examples/network/googlesuggest/googlesuggest.pro
new file mode 100644
index 0000000000..e118dc9c26
--- /dev/null
+++ b/examples/network/googlesuggest/googlesuggest.pro
@@ -0,0 +1,9 @@
+QT += network
+SOURCES = main.cpp searchbox.cpp googlesuggest.cpp
+HEADERS = searchbox.h googlesuggest.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/googlesuggest
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/googlesuggest
+INSTALLS += target sources
diff --git a/examples/network/googlesuggest/main.cpp b/examples/network/googlesuggest/main.cpp
new file mode 100644
index 0000000000..f20e8f6c0e
--- /dev/null
+++ b/examples/network/googlesuggest/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "searchbox.h"
+
+int main(int argc, char * argv[])
+{
+ QApplication app(argc, argv);
+ SearchBox *searchEdit = new SearchBox;
+ searchEdit->show();
+ return app.exec();
+}
diff --git a/examples/network/googlesuggest/searchbox.cpp b/examples/network/googlesuggest/searchbox.cpp
new file mode 100644
index 0000000000..cf22fd1369
--- /dev/null
+++ b/examples/network/googlesuggest/searchbox.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDesktopServices>
+#include <QUrl>
+
+#include "searchbox.h"
+#include "googlesuggest.h"
+
+#define GSEARCH_URL "http://www.google.com/search?q=%1"
+
+//! [1]
+SearchBox::SearchBox(QWidget *parent): QLineEdit(parent)
+{
+ completer = new GSuggestCompletion(this);
+
+ connect(this, SIGNAL(returnPressed()),this, SLOT(doSearch()));
+
+ setWindowTitle("Search with Google");
+
+ adjustSize();
+ resize(400, height());
+ setFocus();
+}
+//! [1]
+
+//! [2]
+void SearchBox::doSearch()
+{
+ completer->preventSuggest();
+ QString url = QString(GSEARCH_URL).arg(text());
+ QDesktopServices::openUrl(QUrl(url));
+}
+//! [2]
+
diff --git a/examples/network/googlesuggest/searchbox.h b/examples/network/googlesuggest/searchbox.h
new file mode 100644
index 0000000000..5ffcbc8614
--- /dev/null
+++ b/examples/network/googlesuggest/searchbox.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 SEARCHBOX_H
+#define SEARCHBOX_H
+
+//! [1]
+#include <QLineEdit>
+
+class GSuggestCompletion;
+
+class SearchBox: public QLineEdit
+{
+ Q_OBJECT
+
+public:
+ SearchBox(QWidget *parent = 0);
+
+protected slots:
+ void doSearch();
+
+private:
+ GSuggestCompletion *completer;
+//! [1]
+};
+
+
+#endif // SEARCHBOX_H
diff --git a/examples/network/http/authenticationdialog.ui b/examples/network/http/authenticationdialog.ui
new file mode 100644
index 0000000000..82d908cffb
--- /dev/null
+++ b/examples/network/http/authenticationdialog.ui
@@ -0,0 +1,129 @@
+<ui version="4.0" >
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>389</width>
+ <height>243</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Http authentication required</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" colspan="2" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>You need to supply a Username and a Password to access this site</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Username:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLineEdit" name="userEdit" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="passwordEdit" />
+ </item>
+ <item row="5" column="0" colspan="2" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Site:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLabel" name="siteDescription" >
+ <property name="font" >
+ <font>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
+ <property name="text" >
+ <string>%1 at %2</string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>Dialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>Dialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/network/http/http.pro b/examples/network/http/http.pro
new file mode 100644
index 0000000000..4f17850cc8
--- /dev/null
+++ b/examples/network/http/http.pro
@@ -0,0 +1,13 @@
+HEADERS += httpwindow.h
+SOURCES += httpwindow.cpp \
+ main.cpp
+FORMS += authenticationdialog.ui
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/http
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS http.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/http
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp
new file mode 100644
index 0000000000..874994ab92
--- /dev/null
+++ b/examples/network/http/httpwindow.cpp
@@ -0,0 +1,266 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "httpwindow.h"
+#include "ui_authenticationdialog.h"
+
+HttpWindow::HttpWindow(QWidget *parent)
+ : QDialog(parent)
+{
+#ifndef QT_NO_OPENSSL
+ urlLineEdit = new QLineEdit("https://qt.nokia.com/");
+#else
+ urlLineEdit = new QLineEdit("http://qt.nokia.com/");
+#endif
+
+ urlLabel = new QLabel(tr("&URL:"));
+ urlLabel->setBuddy(urlLineEdit);
+ statusLabel = new QLabel(tr("Please enter the URL of a file you want to "
+ "download."));
+
+ downloadButton = new QPushButton(tr("Download"));
+ downloadButton->setDefault(true);
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ progressDialog = new QProgressDialog(this);
+
+ connect(urlLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(enableDownloadButton()));
+
+ connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
+#ifndef QT_NO_OPENSSL
+ connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
+ this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
+#endif
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
+ connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *topLayout = new QHBoxLayout;
+ topLayout->addWidget(urlLabel);
+ topLayout->addWidget(urlLineEdit);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(topLayout);
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("HTTP"));
+ urlLineEdit->setFocus();
+}
+
+void HttpWindow::startRequest(QUrl url)
+{
+ reply = qnam.get(QNetworkRequest(url));
+ connect(reply, SIGNAL(finished()),
+ this, SLOT(httpFinished()));
+ connect(reply, SIGNAL(readyRead()),
+ this, SLOT(httpReadyRead()));
+ connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(updateDataReadProgress(qint64,qint64)));
+}
+
+void HttpWindow::downloadFile()
+{
+ url = urlLineEdit->text();
+
+ QFileInfo fileInfo(url.path());
+ QString fileName = fileInfo.fileName();
+ if (fileName.isEmpty())
+ fileName = "index.html";
+
+ if (QFile::exists(fileName)) {
+ if (QMessageBox::question(this, tr("HTTP"),
+ tr("There already exists a file called %1 in "
+ "the current directory. Overwrite?").arg(fileName),
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::No)
+ == QMessageBox::No)
+ return;
+ QFile::remove(fileName);
+ }
+
+ file = new QFile(fileName);
+ if (!file->open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("HTTP"),
+ tr("Unable to save the file %1: %2.")
+ .arg(fileName).arg(file->errorString()));
+ delete file;
+ file = 0;
+ return;
+ }
+
+
+ progressDialog->setWindowTitle(tr("HTTP"));
+ progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
+ downloadButton->setEnabled(false);
+
+ // schedule the request
+ httpRequestAborted = false;
+ startRequest(url);
+}
+
+void HttpWindow::cancelDownload()
+{
+ statusLabel->setText(tr("Download canceled."));
+ httpRequestAborted = true;
+ reply->abort();
+ downloadButton->setEnabled(true);
+}
+
+void HttpWindow::httpFinished()
+{
+ if (httpRequestAborted) {
+ if (file) {
+ file->close();
+ file->remove();
+ delete file;
+ file = 0;
+ }
+ reply->deleteLater();
+ progressDialog->hide();
+ return;
+ }
+
+ progressDialog->hide();
+ file->flush();
+ file->close();
+
+
+ QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (reply->error()) {
+ file->remove();
+ QMessageBox::information(this, tr("HTTP"),
+ tr("Download failed: %1.")
+ .arg(reply->errorString()));
+ downloadButton->setEnabled(true);
+ } else if (!redirectionTarget.isNull()) {
+ QUrl newUrl = url.resolved(redirectionTarget.toUrl());
+ if (QMessageBox::question(this, tr("HTTP"),
+ tr("Redirect to %1 ?").arg(newUrl.toString()),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ url = newUrl;
+ reply->deleteLater();
+ file->open(QIODevice::WriteOnly);
+ file->resize(0);
+ startRequest(url);
+ return;
+ }
+ } else {
+ QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
+ statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
+ downloadButton->setEnabled(true);
+ }
+
+ reply->deleteLater();
+ reply = 0;
+ delete file;
+ file = 0;
+}
+
+void HttpWindow::httpReadyRead()
+{
+ // this slot gets called every time the QNetworkReply has new data.
+ // We read all of its new data and write it into the file.
+ // That way we use less RAM than when reading it at the finished()
+ // signal of the QNetworkReply
+ if (file)
+ file->write(reply->readAll());
+}
+
+void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
+{
+ if (httpRequestAborted)
+ return;
+
+ progressDialog->setMaximum(totalBytes);
+ progressDialog->setValue(bytesRead);
+}
+
+void HttpWindow::enableDownloadButton()
+{
+ downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
+}
+
+void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator)
+{
+ QDialog dlg;
+ Ui::Dialog ui;
+ ui.setupUi(&dlg);
+ dlg.adjustSize();
+ ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host()));
+
+ // Did the URL have information? Fill the UI
+ // This is only relevant if the URL-supplied credentials were wrong
+ ui.userEdit->setText(url.userName());
+ ui.passwordEdit->setText(url.password());
+
+ if (dlg.exec() == QDialog::Accepted) {
+ authenticator->setUser(ui.userEdit->text());
+ authenticator->setPassword(ui.passwordEdit->text());
+ }
+}
+
+#ifndef QT_NO_OPENSSL
+void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
+{
+ QString errorString;
+ foreach (const QSslError &error, errors) {
+ if (!errorString.isEmpty())
+ errorString += ", ";
+ errorString += error.errorString();
+ }
+
+ if (QMessageBox::warning(this, tr("HTTP"),
+ tr("One or more SSL errors has occurred: %1").arg(errorString),
+ QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
+ reply->ignoreSslErrors();
+ }
+}
+#endif
diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h
new file mode 100644
index 0000000000..0ec87af48a
--- /dev/null
+++ b/examples/network/http/httpwindow.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HTTPWINDOW_H
+#define HTTPWINDOW_H
+
+#include <QDialog>
+#include <QNetworkAccessManager>
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QFile;
+class QLabel;
+class QLineEdit;
+class QProgressDialog;
+class QPushButton;
+class QSslError;
+class QAuthenticator;
+class QNetworkReply;
+
+
+QT_END_NAMESPACE
+
+class HttpWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ HttpWindow(QWidget *parent = 0);
+
+ void startRequest(QUrl url);
+
+private slots:
+ void downloadFile();
+ void cancelDownload();
+ void httpFinished();
+ void httpReadyRead();
+ void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
+ void enableDownloadButton();
+ void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *);
+#ifndef QT_NO_OPENSSL
+ void sslErrors(QNetworkReply*,const QList<QSslError> &errors);
+#endif
+
+private:
+ QLabel *statusLabel;
+ QLabel *urlLabel;
+ QLineEdit *urlLineEdit;
+ QProgressDialog *progressDialog;
+ QPushButton *downloadButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QUrl url;
+ QNetworkAccessManager qnam;
+ QNetworkReply *reply;
+ QFile *file;
+ int httpGetId;
+ bool httpRequestAborted;
+};
+
+#endif
diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp
new file mode 100644
index 0000000000..4c4f61c775
--- /dev/null
+++ b/examples/network/http/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "httpwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ HttpWindow httpWin;
+ httpWin.show();
+ return httpWin.exec();
+}
diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp
new file mode 100644
index 0000000000..50a191e9ee
--- /dev/null
+++ b/examples/network/loopback/dialog.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "dialog.h"
+
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+static const int TotalBytes = 50 * 1024 * 1024;
+#else
+static const int TotalBytes = 5 * 1024 * 1024;
+#endif
+static const int PayloadSize = 64 * 1024; // 64 KB
+
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent)
+{
+ clientProgressBar = new QProgressBar;
+ clientStatusLabel = new QLabel(tr("Client ready"));
+ serverProgressBar = new QProgressBar;
+ serverStatusLabel = new QLabel(tr("Server ready"));
+
+ startButton = new QPushButton(tr("&Start"));
+ quitButton = new QPushButton(tr("&Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(startButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(&tcpServer, SIGNAL(newConnection()),
+ this, SLOT(acceptConnection()));
+ connect(&tcpClient, SIGNAL(connected()), this, SLOT(startTransfer()));
+ connect(&tcpClient, SIGNAL(bytesWritten(qint64)),
+ this, SLOT(updateClientProgress(qint64)));
+ connect(&tcpClient, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(displayError(QAbstractSocket::SocketError)));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(clientProgressBar);
+ mainLayout->addWidget(clientStatusLabel);
+ mainLayout->addWidget(serverProgressBar);
+ mainLayout->addWidget(serverStatusLabel);
+ mainLayout->addStretch(1);
+ mainLayout->addSpacing(10);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Loopback"));
+}
+
+void Dialog::start()
+{
+ startButton->setEnabled(false);
+
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(Qt::WaitCursor);
+#endif
+
+ bytesWritten = 0;
+ bytesReceived = 0;
+
+ while (!tcpServer.isListening() && !tcpServer.listen()) {
+ QMessageBox::StandardButton ret = QMessageBox::critical(this,
+ tr("Loopback"),
+ tr("Unable to start the test: %1.")
+ .arg(tcpServer.errorString()),
+ QMessageBox::Retry
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Cancel)
+ return;
+ }
+
+ serverStatusLabel->setText(tr("Listening"));
+ clientStatusLabel->setText(tr("Connecting"));
+ tcpClient.connectToHost(QHostAddress::LocalHost, tcpServer.serverPort());
+}
+
+void Dialog::acceptConnection()
+{
+ tcpServerConnection = tcpServer.nextPendingConnection();
+ connect(tcpServerConnection, SIGNAL(readyRead()),
+ this, SLOT(updateServerProgress()));
+ connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(displayError(QAbstractSocket::SocketError)));
+
+ serverStatusLabel->setText(tr("Accepted connection"));
+ tcpServer.close();
+}
+
+void Dialog::startTransfer()
+{
+ // called when the TCP client connected to the loopback server
+ bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@'));
+ clientStatusLabel->setText(tr("Connected"));
+}
+
+void Dialog::updateServerProgress()
+{
+ bytesReceived += (int)tcpServerConnection->bytesAvailable();
+ tcpServerConnection->readAll();
+
+ serverProgressBar->setMaximum(TotalBytes);
+ serverProgressBar->setValue(bytesReceived);
+ serverStatusLabel->setText(tr("Received %1MB")
+ .arg(bytesReceived / (1024 * 1024)));
+
+ if (bytesReceived == TotalBytes) {
+ tcpServerConnection->close();
+ startButton->setEnabled(true);
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+ }
+}
+
+void Dialog::updateClientProgress(qint64 numBytes)
+{
+ // callen when the TCP client has written some bytes
+ bytesWritten += (int)numBytes;
+
+ // only write more if not finished and when the Qt write buffer is below a certain size.
+ if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize)
+ bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@'));
+
+ clientProgressBar->setMaximum(TotalBytes);
+ clientProgressBar->setValue(bytesWritten);
+ clientStatusLabel->setText(tr("Sent %1MB")
+ .arg(bytesWritten / (1024 * 1024)));
+}
+
+void Dialog::displayError(QAbstractSocket::SocketError socketError)
+{
+ if (socketError == QTcpSocket::RemoteHostClosedError)
+ return;
+
+ QMessageBox::information(this, tr("Network error"),
+ tr("The following error occurred: %1.")
+ .arg(tcpClient.errorString()));
+
+ tcpClient.close();
+ tcpServer.close();
+ clientProgressBar->reset();
+ serverProgressBar->reset();
+ clientStatusLabel->setText(tr("Client ready"));
+ serverStatusLabel->setText(tr("Server ready"));
+ startButton->setEnabled(true);
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+}
diff --git a/examples/network/loopback/dialog.h b/examples/network/loopback/dialog.h
new file mode 100644
index 0000000000..09b4366e19
--- /dev/null
+++ b/examples/network/loopback/dialog.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+#include <QTcpServer>
+#include <QTcpSocket>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QProgressBar;
+class QPushButton;
+class QTcpServer;
+class QTcpSocket;
+QT_END_NAMESPACE
+
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog(QWidget *parent = 0);
+
+public slots:
+ void start();
+ void acceptConnection();
+ void startTransfer();
+ void updateServerProgress();
+ void updateClientProgress(qint64 numBytes);
+ void displayError(QAbstractSocket::SocketError socketError);
+
+private:
+ QProgressBar *clientProgressBar;
+ QProgressBar *serverProgressBar;
+ QLabel *clientStatusLabel;
+ QLabel *serverStatusLabel;
+ QPushButton *startButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+
+ QTcpServer tcpServer;
+ QTcpSocket tcpClient;
+ QTcpSocket *tcpServerConnection;
+ int bytesToWrite;
+ int bytesWritten;
+ int bytesReceived;
+};
+
+#endif
diff --git a/examples/network/loopback/loopback.pro b/examples/network/loopback/loopback.pro
new file mode 100644
index 0000000000..daf4fc35f5
--- /dev/null
+++ b/examples/network/loopback/loopback.pro
@@ -0,0 +1,12 @@
+HEADERS = dialog.h
+SOURCES = dialog.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/loopback
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loopback.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/loopback
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/loopback/main.cpp b/examples/network/loopback/main.cpp
new file mode 100644
index 0000000000..6810b795fc
--- /dev/null
+++ b/examples/network/loopback/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.show();
+ return dialog.exec();
+}
diff --git a/examples/network/multicastreceiver/main.cpp b/examples/network/multicastreceiver/main.cpp
new file mode 100644
index 0000000000..041163178d
--- /dev/null
+++ b/examples/network/multicastreceiver/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "receiver.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Receiver receiver;
+ receiver.show();
+ return receiver.exec();
+}
diff --git a/examples/network/multicastreceiver/multicastreceiver.pro b/examples/network/multicastreceiver/multicastreceiver.pro
new file mode 100644
index 0000000000..8c13c34450
--- /dev/null
+++ b/examples/network/multicastreceiver/multicastreceiver.pro
@@ -0,0 +1,12 @@
+HEADERS = receiver.h
+SOURCES = receiver.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/multicastreceiver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multicastreceiver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/multicastreceiver
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/multicastreceiver/receiver.cpp b/examples/network/multicastreceiver/receiver.cpp
new file mode 100644
index 0000000000..77446b93ff
--- /dev/null
+++ b/examples/network/multicastreceiver/receiver.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "receiver.h"
+
+Receiver::Receiver(QWidget *parent)
+ : QDialog(parent)
+{
+ groupAddress = QHostAddress("239.255.43.21");
+
+ statusLabel = new QLabel(tr("Listening for multicasted messages"));
+ quitButton = new QPushButton(tr("&Quit"));
+
+ udpSocket = new QUdpSocket(this);
+ udpSocket->bind(45454, QUdpSocket::ShareAddress);
+ udpSocket->joinMulticastGroup(groupAddress);
+
+ connect(udpSocket, SIGNAL(readyRead()),
+ this, SLOT(processPendingDatagrams()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Multicast Receiver"));
+}
+
+void Receiver::processPendingDatagrams()
+{
+ while (udpSocket->hasPendingDatagrams()) {
+ QByteArray datagram;
+ datagram.resize(udpSocket->pendingDatagramSize());
+ udpSocket->readDatagram(datagram.data(), datagram.size());
+ statusLabel->setText(tr("Received datagram: \"%1\"")
+ .arg(datagram.data()));
+ }
+}
diff --git a/examples/network/multicastreceiver/receiver.h b/examples/network/multicastreceiver/receiver.h
new file mode 100644
index 0000000000..fd1a67377f
--- /dev/null
+++ b/examples/network/multicastreceiver/receiver.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RECEIVER_H
+#define RECEIVER_H
+
+#include <QDialog>
+#include <QHostAddress>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QUdpSocket;
+QT_END_NAMESPACE
+
+class Receiver : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Receiver(QWidget *parent = 0);
+
+private slots:
+ void processPendingDatagrams();
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ QUdpSocket *udpSocket;
+ QHostAddress groupAddress;
+};
+
+#endif
diff --git a/examples/network/multicastsender/main.cpp b/examples/network/multicastsender/main.cpp
new file mode 100644
index 0000000000..56e35c9540
--- /dev/null
+++ b/examples/network/multicastsender/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "sender.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Sender sender;
+ sender.show();
+ return sender.exec();
+}
diff --git a/examples/network/multicastsender/multicastsender.pro b/examples/network/multicastsender/multicastsender.pro
new file mode 100644
index 0000000000..db97334d8e
--- /dev/null
+++ b/examples/network/multicastsender/multicastsender.pro
@@ -0,0 +1,12 @@
+HEADERS = sender.h
+SOURCES = sender.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/multicastsender
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS multicastsender.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/multicastsender
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/multicastsender/sender.cpp b/examples/network/multicastsender/sender.cpp
new file mode 100644
index 0000000000..aab94aa42a
--- /dev/null
+++ b/examples/network/multicastsender/sender.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "sender.h"
+
+Sender::Sender(QWidget *parent)
+ : QDialog(parent)
+{
+ groupAddress = QHostAddress("239.255.43.21");
+
+ statusLabel = new QLabel(tr("Ready to multicast datagrams to group %1 on port 45454").arg(groupAddress.toString()));
+
+ ttlLabel = new QLabel(tr("TTL for multicast datagrams:"));
+ ttlSpinBox = new QSpinBox;
+ ttlSpinBox->setRange(0, 255);
+
+ QHBoxLayout *ttlLayout = new QHBoxLayout;
+ ttlLayout->addWidget(ttlLabel);
+ ttlLayout->addWidget(ttlSpinBox);
+
+ startButton = new QPushButton(tr("&Start"));
+ quitButton = new QPushButton(tr("&Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(startButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ timer = new QTimer(this);
+ udpSocket = new QUdpSocket(this);
+ messageNo = 1;
+
+ connect(ttlSpinBox, SIGNAL(valueChanged(int)), this, SLOT(ttlChanged(int)));
+ connect(startButton, SIGNAL(clicked()), this, SLOT(startSending()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram()));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(ttlLayout);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Multicast Sender"));
+ ttlSpinBox->setValue(1);
+}
+
+void Sender::ttlChanged(int newTtl)
+{
+ udpSocket->setSocketOption(QAbstractSocket::MulticastTtlOption, newTtl);
+}
+
+void Sender::startSending()
+{
+ startButton->setEnabled(false);
+ timer->start(1000);
+}
+
+void Sender::sendDatagram()
+{
+ statusLabel->setText(tr("Now sending datagram %1").arg(messageNo));
+ QByteArray datagram = "Multicast message " + QByteArray::number(messageNo);
+ udpSocket->writeDatagram(datagram.data(), datagram.size(),
+ groupAddress, 45454);
+ ++messageNo;
+}
diff --git a/examples/network/multicastsender/sender.h b/examples/network/multicastsender/sender.h
new file mode 100644
index 0000000000..75ce4c93ea
--- /dev/null
+++ b/examples/network/multicastsender/sender.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SENDER_H
+#define SENDER_H
+
+#include <QDialog>
+#include <QHostAddress>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLabel;
+class QPushButton;
+class QTimer;
+class QUdpSocket;
+class QSpinBox;
+QT_END_NAMESPACE
+
+class Sender : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Sender(QWidget *parent = 0);
+
+private slots:
+ void ttlChanged(int newTtl);
+ void startSending();
+ void sendDatagram();
+
+private:
+ QLabel *statusLabel;
+ QLabel *ttlLabel;
+ QSpinBox *ttlSpinBox;
+ QPushButton *startButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+ QUdpSocket *udpSocket;
+ QTimer *timer;
+ QHostAddress groupAddress;
+ int messageNo;
+};
+
+#endif
diff --git a/examples/network/network-chat/chatdialog.cpp b/examples/network/network-chat/chatdialog.cpp
new file mode 100644
index 0000000000..cdb29ea518
--- /dev/null
+++ b/examples/network/network-chat/chatdialog.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "chatdialog.h"
+
+ChatDialog::ChatDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ lineEdit->setFocusPolicy(Qt::StrongFocus);
+ textEdit->setFocusPolicy(Qt::NoFocus);
+ textEdit->setReadOnly(true);
+ listWidget->setFocusPolicy(Qt::NoFocus);
+
+ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ connect(&client, SIGNAL(newMessage(QString,QString)),
+ this, SLOT(appendMessage(QString,QString)));
+ connect(&client, SIGNAL(newParticipant(QString)),
+ this, SLOT(newParticipant(QString)));
+ connect(&client, SIGNAL(participantLeft(QString)),
+ this, SLOT(participantLeft(QString)));
+
+ myNickName = client.nickName();
+ newParticipant(myNickName);
+ tableFormat.setBorder(0);
+ QTimer::singleShot(10 * 1000, this, SLOT(showInformation()));
+}
+
+void ChatDialog::appendMessage(const QString &from, const QString &message)
+{
+ if (from.isEmpty() || message.isEmpty())
+ return;
+
+ QTextCursor cursor(textEdit->textCursor());
+ cursor.movePosition(QTextCursor::End);
+ QTextTable *table = cursor.insertTable(1, 2, tableFormat);
+ table->cellAt(0, 0).firstCursorPosition().insertText('<' + from + "> ");
+ table->cellAt(0, 1).firstCursorPosition().insertText(message);
+ QScrollBar *bar = textEdit->verticalScrollBar();
+ bar->setValue(bar->maximum());
+}
+
+void ChatDialog::returnPressed()
+{
+ QString text = lineEdit->text();
+ if (text.isEmpty())
+ return;
+
+ if (text.startsWith(QChar('/'))) {
+ QColor color = textEdit->textColor();
+ textEdit->setTextColor(Qt::red);
+ textEdit->append(tr("! Unknown command: %1")
+ .arg(text.left(text.indexOf(' '))));
+ textEdit->setTextColor(color);
+ } else {
+ client.sendMessage(text);
+ appendMessage(myNickName, text);
+ }
+
+ lineEdit->clear();
+}
+
+void ChatDialog::newParticipant(const QString &nick)
+{
+ if (nick.isEmpty())
+ return;
+
+ QColor color = textEdit->textColor();
+ textEdit->setTextColor(Qt::gray);
+ textEdit->append(tr("* %1 has joined").arg(nick));
+ textEdit->setTextColor(color);
+ listWidget->addItem(nick);
+}
+
+void ChatDialog::participantLeft(const QString &nick)
+{
+ if (nick.isEmpty())
+ return;
+
+ QList<QListWidgetItem *> items = listWidget->findItems(nick,
+ Qt::MatchExactly);
+ if (items.isEmpty())
+ return;
+
+ delete items.at(0);
+ QColor color = textEdit->textColor();
+ textEdit->setTextColor(Qt::gray);
+ textEdit->append(tr("* %1 has left").arg(nick));
+ textEdit->setTextColor(color);
+}
+
+void ChatDialog::showInformation()
+{
+ if (listWidget->count() == 1) {
+ QMessageBox::information(this, tr("Chat"),
+ tr("Launch several instances of this "
+ "program on your local network and "
+ "start chatting!"));
+ }
+}
diff --git a/examples/network/network-chat/chatdialog.h b/examples/network/network-chat/chatdialog.h
new file mode 100644
index 0000000000..258206a905
--- /dev/null
+++ b/examples/network/network-chat/chatdialog.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CHATDIALOG_H
+#define CHATDIALOG_H
+
+#include "ui_chatdialog.h"
+#include "client.h"
+
+class ChatDialog : public QDialog, private Ui::ChatDialog
+{
+ Q_OBJECT
+
+public:
+ ChatDialog(QWidget *parent = 0);
+
+public slots:
+ void appendMessage(const QString &from, const QString &message);
+
+private slots:
+ void returnPressed();
+ void newParticipant(const QString &nick);
+ void participantLeft(const QString &nick);
+ void showInformation();
+
+private:
+ Client client;
+ QString myNickName;
+ QTextTableFormat tableFormat;
+};
+
+#endif
diff --git a/examples/network/network-chat/chatdialog.ui b/examples/network/network-chat/chatdialog.ui
new file mode 100644
index 0000000000..c85e0d0f55
--- /dev/null
+++ b/examples/network/network-chat/chatdialog.ui
@@ -0,0 +1,79 @@
+<ui version="4.0" >
+ <class>ChatDialog</class>
+ <widget class="QDialog" name="ChatDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>513</width>
+ <height>349</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Chat</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="textEdit" >
+ <property name="focusPolicy" >
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidget" >
+ <property name="maximumSize" >
+ <size>
+ <width>180</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="focusPolicy" >
+ <enum>Qt::NoFocus</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Message:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit" />
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/network/network-chat/client.cpp b/examples/network/network-chat/client.cpp
new file mode 100644
index 0000000000..d9f594e8ac
--- /dev/null
+++ b/examples/network/network-chat/client.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtNetwork>
+
+#include "client.h"
+#include "connection.h"
+#include "peermanager.h"
+
+Client::Client()
+{
+ peerManager = new PeerManager(this);
+ peerManager->setServerPort(server.serverPort());
+ peerManager->startBroadcasting();
+
+ QObject::connect(peerManager, SIGNAL(newConnection(Connection*)),
+ this, SLOT(newConnection(Connection*)));
+ QObject::connect(&server, SIGNAL(newConnection(Connection*)),
+ this, SLOT(newConnection(Connection*)));
+}
+
+void Client::sendMessage(const QString &message)
+{
+ if (message.isEmpty())
+ return;
+
+ QList<Connection *> connections = peers.values();
+ foreach (Connection *connection, connections)
+ connection->sendMessage(message);
+}
+
+QString Client::nickName() const
+{
+ return QString(peerManager->userName()) + '@' + QHostInfo::localHostName()
+ + ':' + QString::number(server.serverPort());
+}
+
+bool Client::hasConnection(const QHostAddress &senderIp, int senderPort) const
+{
+ if (senderPort == -1)
+ return peers.contains(senderIp);
+
+ if (!peers.contains(senderIp))
+ return false;
+
+ QList<Connection *> connections = peers.values(senderIp);
+ foreach (Connection *connection, connections) {
+ if (connection->peerPort() == senderPort)
+ return true;
+ }
+
+ return false;
+}
+
+void Client::newConnection(Connection *connection)
+{
+ connection->setGreetingMessage(peerManager->userName());
+
+ connect(connection, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(connectionError(QAbstractSocket::SocketError)));
+ connect(connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
+ connect(connection, SIGNAL(readyForUse()), this, SLOT(readyForUse()));
+}
+
+void Client::readyForUse()
+{
+ Connection *connection = qobject_cast<Connection *>(sender());
+ if (!connection || hasConnection(connection->peerAddress(),
+ connection->peerPort()))
+ return;
+
+ connect(connection, SIGNAL(newMessage(QString,QString)),
+ this, SIGNAL(newMessage(QString,QString)));
+
+ peers.insert(connection->peerAddress(), connection);
+ QString nick = connection->name();
+ if (!nick.isEmpty())
+ emit newParticipant(nick);
+}
+
+void Client::disconnected()
+{
+ if (Connection *connection = qobject_cast<Connection *>(sender()))
+ removeConnection(connection);
+}
+
+void Client::connectionError(QAbstractSocket::SocketError /* socketError */)
+{
+ if (Connection *connection = qobject_cast<Connection *>(sender()))
+ removeConnection(connection);
+}
+
+void Client::removeConnection(Connection *connection)
+{
+ if (peers.contains(connection->peerAddress())) {
+ peers.remove(connection->peerAddress());
+ QString nick = connection->name();
+ if (!nick.isEmpty())
+ emit participantLeft(nick);
+ }
+ connection->deleteLater();
+}
diff --git a/examples/network/network-chat/client.h b/examples/network/network-chat/client.h
new file mode 100644
index 0000000000..317fef36a8
--- /dev/null
+++ b/examples/network/network-chat/client.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <QAbstractSocket>
+#include <QHash>
+#include <QHostAddress>
+
+#include "server.h"
+
+class PeerManager;
+
+class Client : public QObject
+{
+ Q_OBJECT
+
+public:
+ Client();
+
+ void sendMessage(const QString &message);
+ QString nickName() const;
+ bool hasConnection(const QHostAddress &senderIp, int senderPort = -1) const;
+
+signals:
+ void newMessage(const QString &from, const QString &message);
+ void newParticipant(const QString &nick);
+ void participantLeft(const QString &nick);
+
+private slots:
+ void newConnection(Connection *connection);
+ void connectionError(QAbstractSocket::SocketError socketError);
+ void disconnected();
+ void readyForUse();
+
+private:
+ void removeConnection(Connection *connection);
+
+ PeerManager *peerManager;
+ Server server;
+ QMultiHash<QHostAddress, Connection *> peers;
+};
+
+#endif
diff --git a/examples/network/network-chat/connection.cpp b/examples/network/network-chat/connection.cpp
new file mode 100644
index 0000000000..9171d1fc5f
--- /dev/null
+++ b/examples/network/network-chat/connection.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "connection.h"
+
+#include <QtNetwork>
+
+static const int TransferTimeout = 30 * 1000;
+static const int PongTimeout = 60 * 1000;
+static const int PingInterval = 5 * 1000;
+static const char SeparatorToken = ' ';
+
+Connection::Connection(QObject *parent)
+ : QTcpSocket(parent)
+{
+ greetingMessage = tr("undefined");
+ username = tr("unknown");
+ state = WaitingForGreeting;
+ currentDataType = Undefined;
+ numBytesForCurrentDataType = -1;
+ transferTimerId = 0;
+ isGreetingMessageSent = false;
+ pingTimer.setInterval(PingInterval);
+
+ QObject::connect(this, SIGNAL(readyRead()), this, SLOT(processReadyRead()));
+ QObject::connect(this, SIGNAL(disconnected()), &pingTimer, SLOT(stop()));
+ QObject::connect(&pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
+ QObject::connect(this, SIGNAL(connected()),
+ this, SLOT(sendGreetingMessage()));
+}
+
+QString Connection::name() const
+{
+ return username;
+}
+
+void Connection::setGreetingMessage(const QString &message)
+{
+ greetingMessage = message;
+}
+
+bool Connection::sendMessage(const QString &message)
+{
+ if (message.isEmpty())
+ return false;
+
+ QByteArray msg = message.toUtf8();
+ QByteArray data = "MESSAGE " + QByteArray::number(msg.size()) + ' ' + msg;
+ return write(data) == data.size();
+}
+
+void Connection::timerEvent(QTimerEvent *timerEvent)
+{
+ if (timerEvent->timerId() == transferTimerId) {
+ abort();
+ killTimer(transferTimerId);
+ transferTimerId = 0;
+ }
+}
+
+void Connection::processReadyRead()
+{
+ if (state == WaitingForGreeting) {
+ if (!readProtocolHeader())
+ return;
+ if (currentDataType != Greeting) {
+ abort();
+ return;
+ }
+ state = ReadingGreeting;
+ }
+
+ if (state == ReadingGreeting) {
+ if (!hasEnoughData())
+ return;
+
+ buffer = read(numBytesForCurrentDataType);
+ if (buffer.size() != numBytesForCurrentDataType) {
+ abort();
+ return;
+ }
+
+ username = QString(buffer) + '@' + peerAddress().toString() + ':'
+ + QString::number(peerPort());
+ currentDataType = Undefined;
+ numBytesForCurrentDataType = 0;
+ buffer.clear();
+
+ if (!isValid()) {
+ abort();
+ return;
+ }
+
+ if (!isGreetingMessageSent)
+ sendGreetingMessage();
+
+ pingTimer.start();
+ pongTime.start();
+ state = ReadyForUse;
+ emit readyForUse();
+ }
+
+ do {
+ if (currentDataType == Undefined) {
+ if (!readProtocolHeader())
+ return;
+ }
+ if (!hasEnoughData())
+ return;
+ processData();
+ } while (bytesAvailable() > 0);
+}
+
+void Connection::sendPing()
+{
+ if (pongTime.elapsed() > PongTimeout) {
+ abort();
+ return;
+ }
+
+ write("PING 1 p");
+}
+
+void Connection::sendGreetingMessage()
+{
+ QByteArray greeting = greetingMessage.toUtf8();
+ QByteArray data = "GREETING " + QByteArray::number(greeting.size()) + ' ' + greeting;
+ if (write(data) == data.size())
+ isGreetingMessageSent = true;
+}
+
+int Connection::readDataIntoBuffer(int maxSize)
+{
+ if (maxSize > MaxBufferSize)
+ return 0;
+
+ int numBytesBeforeRead = buffer.size();
+ if (numBytesBeforeRead == MaxBufferSize) {
+ abort();
+ return 0;
+ }
+
+ while (bytesAvailable() > 0 && buffer.size() < maxSize) {
+ buffer.append(read(1));
+ if (buffer.endsWith(SeparatorToken))
+ break;
+ }
+ return buffer.size() - numBytesBeforeRead;
+}
+
+int Connection::dataLengthForCurrentDataType()
+{
+ if (bytesAvailable() <= 0 || readDataIntoBuffer() <= 0
+ || !buffer.endsWith(SeparatorToken))
+ return 0;
+
+ buffer.chop(1);
+ int number = buffer.toInt();
+ buffer.clear();
+ return number;
+}
+
+bool Connection::readProtocolHeader()
+{
+ if (transferTimerId) {
+ killTimer(transferTimerId);
+ transferTimerId = 0;
+ }
+
+ if (readDataIntoBuffer() <= 0) {
+ transferTimerId = startTimer(TransferTimeout);
+ return false;
+ }
+
+ if (buffer == "PING ") {
+ currentDataType = Ping;
+ } else if (buffer == "PONG ") {
+ currentDataType = Pong;
+ } else if (buffer == "MESSAGE ") {
+ currentDataType = PlainText;
+ } else if (buffer == "GREETING ") {
+ currentDataType = Greeting;
+ } else {
+ currentDataType = Undefined;
+ abort();
+ return false;
+ }
+
+ buffer.clear();
+ numBytesForCurrentDataType = dataLengthForCurrentDataType();
+ return true;
+}
+
+bool Connection::hasEnoughData()
+{
+ if (transferTimerId) {
+ QObject::killTimer(transferTimerId);
+ transferTimerId = 0;
+ }
+
+ if (numBytesForCurrentDataType <= 0)
+ numBytesForCurrentDataType = dataLengthForCurrentDataType();
+
+ if (bytesAvailable() < numBytesForCurrentDataType
+ || numBytesForCurrentDataType <= 0) {
+ transferTimerId = startTimer(TransferTimeout);
+ return false;
+ }
+
+ return true;
+}
+
+void Connection::processData()
+{
+ buffer = read(numBytesForCurrentDataType);
+ if (buffer.size() != numBytesForCurrentDataType) {
+ abort();
+ return;
+ }
+
+ switch (currentDataType) {
+ case PlainText:
+ emit newMessage(username, QString::fromUtf8(buffer));
+ break;
+ case Ping:
+ write("PONG 1 p");
+ break;
+ case Pong:
+ pongTime.restart();
+ break;
+ default:
+ break;
+ }
+
+ currentDataType = Undefined;
+ numBytesForCurrentDataType = 0;
+ buffer.clear();
+}
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
new file mode 100644
index 0000000000..5db5cc59e8
--- /dev/null
+++ b/examples/network/network-chat/connection.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONNECTION_H
+#define CONNECTION_H
+
+#include <QHostAddress>
+#include <QString>
+#include <QTcpSocket>
+#include <QTime>
+#include <QTimer>
+
+static const int MaxBufferSize = 1024000;
+
+class Connection : public QTcpSocket
+{
+ Q_OBJECT
+
+public:
+ enum ConnectionState {
+ WaitingForGreeting,
+ ReadingGreeting,
+ ReadyForUse
+ };
+ enum DataType {
+ PlainText,
+ Ping,
+ Pong,
+ Greeting,
+ Undefined
+ };
+
+ Connection(QObject *parent = 0);
+
+ QString name() const;
+ void setGreetingMessage(const QString &message);
+ bool sendMessage(const QString &message);
+
+signals:
+ void readyForUse();
+ void newMessage(const QString &from, const QString &message);
+
+protected:
+ void timerEvent(QTimerEvent *timerEvent);
+
+private slots:
+ void processReadyRead();
+ void sendPing();
+ void sendGreetingMessage();
+
+private:
+ int readDataIntoBuffer(int maxSize = MaxBufferSize);
+ int dataLengthForCurrentDataType();
+ bool readProtocolHeader();
+ bool hasEnoughData();
+ void processData();
+
+ QString greetingMessage;
+ QString username;
+ QTimer pingTimer;
+ QTime pongTime;
+ QByteArray buffer;
+ ConnectionState state;
+ DataType currentDataType;
+ int numBytesForCurrentDataType;
+ int transferTimerId;
+ bool isGreetingMessageSent;
+};
+
+#endif
diff --git a/examples/network/network-chat/main.cpp b/examples/network/network-chat/main.cpp
new file mode 100644
index 0000000000..a126172b74
--- /dev/null
+++ b/examples/network/network-chat/main.cpp
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "chatdialog.h"
+
+#include <QtCore/QSettings>
+#include <QtNetwork/QNetworkConfigurationManager>
+#include <QtNetwork/QNetworkSession>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QNetworkConfigurationManager manager;
+ if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
+ // Get saved network configuration
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
+ settings.endGroup();
+
+ // If the saved network configuration is not currently discovered use the system default
+ QNetworkConfiguration config = manager.configurationFromIdentifier(id);
+ if ((config.state() & QNetworkConfiguration::Discovered) !=
+ QNetworkConfiguration::Discovered) {
+ config = manager.defaultConfiguration();
+ }
+
+ QNetworkSession *networkSession = new QNetworkSession(config, &app);
+ networkSession->open();
+ networkSession->waitForOpened();
+
+ if (networkSession->isOpen()) {
+ // Save the used configuration
+ QNetworkConfiguration config = networkSession->configuration();
+ QString id;
+ if (config.type() == QNetworkConfiguration::UserChoice) {
+ id = networkSession->sessionProperty(
+ QLatin1String("UserChoiceConfiguration")).toString();
+ } else {
+ id = config.identifier();
+ }
+
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
+ settings.endGroup();
+ }
+ }
+
+ ChatDialog dialog;
+#ifdef Q_OS_SYMBIAN
+ // Make application better looking and more usable on small screen
+ dialog.showMaximized();
+#else
+ dialog.show();
+#endif
+ return app.exec();
+}
diff --git a/examples/network/network-chat/network-chat.pro b/examples/network/network-chat/network-chat.pro
new file mode 100644
index 0000000000..11f2d2ef30
--- /dev/null
+++ b/examples/network/network-chat/network-chat.pro
@@ -0,0 +1,26 @@
+HEADERS = chatdialog.h \
+ client.h \
+ connection.h \
+ peermanager.h \
+ server.h
+SOURCES = chatdialog.cpp \
+ client.cpp \
+ connection.cpp \
+ main.cpp \
+ peermanager.cpp \
+ server.cpp
+FORMS = chatdialog.ui
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/network-chat
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS network-chat.pro *.chat
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/network-chat
+INSTALLS += target sources
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ LIBS += -lcharconv
+ TARGET.CAPABILITY = "NetworkServices ReadUserData WriteUserData"
+ TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
+}
diff --git a/examples/network/network-chat/peermanager.cpp b/examples/network/network-chat/peermanager.cpp
new file mode 100644
index 0000000000..0e5bd1724e
--- /dev/null
+++ b/examples/network/network-chat/peermanager.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtNetwork>
+
+#include "client.h"
+#include "connection.h"
+#include "peermanager.h"
+
+static const qint32 BroadcastInterval = 2000;
+static const unsigned broadcastPort = 45000;
+
+PeerManager::PeerManager(Client *client)
+ : QObject(client)
+{
+ this->client = client;
+
+ QStringList envVariables;
+ envVariables << "USERNAME.*" << "USER.*" << "USERDOMAIN.*"
+ << "HOSTNAME.*" << "DOMAINNAME.*";
+
+ QStringList environment = QProcess::systemEnvironment();
+ foreach (QString string, envVariables) {
+ int index = environment.indexOf(QRegExp(string));
+ if (index != -1) {
+ QStringList stringList = environment.at(index).split('=');
+ if (stringList.size() == 2) {
+ username = stringList.at(1).toUtf8();
+ break;
+ }
+ }
+ }
+
+ if (username.isEmpty())
+#ifndef Q_OS_SYMBIAN
+ username = "unknown";
+#else
+ username = "QtS60";
+#endif
+
+ updateAddresses();
+ serverPort = 0;
+
+ broadcastSocket.bind(QHostAddress::Any, broadcastPort, QUdpSocket::ShareAddress
+ | QUdpSocket::ReuseAddressHint);
+ connect(&broadcastSocket, SIGNAL(readyRead()),
+ this, SLOT(readBroadcastDatagram()));
+
+ broadcastTimer.setInterval(BroadcastInterval);
+ connect(&broadcastTimer, SIGNAL(timeout()),
+ this, SLOT(sendBroadcastDatagram()));
+}
+
+void PeerManager::setServerPort(int port)
+{
+ serverPort = port;
+}
+
+QByteArray PeerManager::userName() const
+{
+ return username;
+}
+
+void PeerManager::startBroadcasting()
+{
+ broadcastTimer.start();
+}
+
+bool PeerManager::isLocalHostAddress(const QHostAddress &address)
+{
+ foreach (QHostAddress localAddress, ipAddresses) {
+ if (address == localAddress)
+ return true;
+ }
+ return false;
+}
+
+void PeerManager::sendBroadcastDatagram()
+{
+ QByteArray datagram(username);
+ datagram.append('@');
+ datagram.append(QByteArray::number(serverPort));
+
+ bool validBroadcastAddresses = true;
+ foreach (QHostAddress address, broadcastAddresses) {
+ if (broadcastSocket.writeDatagram(datagram, address,
+ broadcastPort) == -1)
+ validBroadcastAddresses = false;
+ }
+
+ if (!validBroadcastAddresses)
+ updateAddresses();
+}
+
+void PeerManager::readBroadcastDatagram()
+{
+ while (broadcastSocket.hasPendingDatagrams()) {
+ QHostAddress senderIp;
+ quint16 senderPort;
+ QByteArray datagram;
+ datagram.resize(broadcastSocket.pendingDatagramSize());
+ if (broadcastSocket.readDatagram(datagram.data(), datagram.size(),
+ &senderIp, &senderPort) == -1)
+ continue;
+
+ QList<QByteArray> list = datagram.split('@');
+ if (list.size() != 2)
+ continue;
+
+ int senderServerPort = list.at(1).toInt();
+ if (isLocalHostAddress(senderIp) && senderServerPort == serverPort)
+ continue;
+
+ if (!client->hasConnection(senderIp)) {
+ Connection *connection = new Connection(this);
+ emit newConnection(connection);
+ connection->connectToHost(senderIp, senderServerPort);
+ }
+ }
+}
+
+void PeerManager::updateAddresses()
+{
+ broadcastAddresses.clear();
+ ipAddresses.clear();
+ foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
+ foreach (QNetworkAddressEntry entry, interface.addressEntries()) {
+ QHostAddress broadcastAddress = entry.broadcast();
+ if (broadcastAddress != QHostAddress::Null && entry.ip() != QHostAddress::LocalHost) {
+ broadcastAddresses << broadcastAddress;
+ ipAddresses << entry.ip();
+ }
+ }
+ }
+}
diff --git a/examples/network/network-chat/peermanager.h b/examples/network/network-chat/peermanager.h
new file mode 100644
index 0000000000..a061bbbb53
--- /dev/null
+++ b/examples/network/network-chat/peermanager.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PEERMANAGER_H
+#define PEERMANAGER_H
+
+#include <QByteArray>
+#include <QList>
+#include <QObject>
+#include <QTimer>
+#include <QUdpSocket>
+
+class Client;
+class Connection;
+
+class PeerManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ PeerManager(Client *client);
+
+ void setServerPort(int port);
+ QByteArray userName() const;
+ void startBroadcasting();
+ bool isLocalHostAddress(const QHostAddress &address);
+
+signals:
+ void newConnection(Connection *connection);
+
+private slots:
+ void sendBroadcastDatagram();
+ void readBroadcastDatagram();
+
+private:
+ void updateAddresses();
+
+ Client *client;
+ QList<QHostAddress> broadcastAddresses;
+ QList<QHostAddress> ipAddresses;
+ QUdpSocket broadcastSocket;
+ QTimer broadcastTimer;
+ QByteArray username;
+ int serverPort;
+};
+
+#endif
diff --git a/examples/network/network-chat/server.cpp b/examples/network/network-chat/server.cpp
new file mode 100644
index 0000000000..4a3a28298a
--- /dev/null
+++ b/examples/network/network-chat/server.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtNetwork>
+
+#include "connection.h"
+#include "server.h"
+
+Server::Server(QObject *parent)
+ : QTcpServer(parent)
+{
+ listen(QHostAddress::Any);
+}
+
+void Server::incomingConnection(int socketDescriptor)
+{
+ Connection *connection = new Connection(this);
+ connection->setSocketDescriptor(socketDescriptor);
+ emit newConnection(connection);
+}
diff --git a/examples/network/network-chat/server.h b/examples/network/network-chat/server.h
new file mode 100644
index 0000000000..0d88c873da
--- /dev/null
+++ b/examples/network/network-chat/server.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SERVER_H
+#define SERVER_H
+
+#include <QTcpServer>
+
+class Connection;
+
+class Server : public QTcpServer
+{
+ Q_OBJECT
+
+public:
+ Server(QObject *parent = 0);
+
+signals:
+ void newConnection(Connection *connection);
+
+protected:
+ void incomingConnection(int socketDescriptor);
+};
+
+#endif
diff --git a/examples/network/network.pro b/examples/network/network.pro
new file mode 100644
index 0000000000..1ebb499f8b
--- /dev/null
+++ b/examples/network/network.pro
@@ -0,0 +1,41 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ download \
+ downloadmanager
+
+!contains(QT_CONFIG, no-gui) {
+ SUBDIRS += \
+ blockingfortuneclient \
+ broadcastreceiver \
+ broadcastsender \
+ fortuneclient \
+ fortuneserver \
+ qftp \
+ http \
+ loopback \
+ threadedfortuneserver \
+ googlesuggest \
+ torrent \
+ bearermonitor \
+ multicastreceiver \
+ multicastsender
+
+ contains(QT_CONFIG, svg) {
+ SUBDIRS += bearercloud
+ }
+
+ # no QProcess
+ !vxworks:!qnx:SUBDIRS += network-chat
+
+ contains(QT_CONFIG, openssl):SUBDIRS += securesocketclient
+ contains(QT_CONFIG, openssl-linked):SUBDIRS += securesocketclient
+}
+
+symbian: SUBDIRS = qftp
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS network.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/qftp/ftp.qrc b/examples/network/qftp/ftp.qrc
new file mode 100644
index 0000000000..b598ab8829
--- /dev/null
+++ b/examples/network/qftp/ftp.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/cdtoparent.png</file>
+ <file>images/dir.png</file>
+ <file>images/file.png</file>
+</qresource>
+</RCC>
diff --git a/examples/network/qftp/ftpwindow.cpp b/examples/network/qftp/ftpwindow.cpp
new file mode 100644
index 0000000000..c3e629f4f2
--- /dev/null
+++ b/examples/network/qftp/ftpwindow.cpp
@@ -0,0 +1,407 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include "ftpwindow.h"
+
+FtpWindow::FtpWindow(QWidget *parent)
+ : QDialog(parent), ftp(0), networkSession(0)
+{
+ ftpServerLabel = new QLabel(tr("Ftp &server:"));
+ ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com");
+ ftpServerLabel->setBuddy(ftpServerLineEdit);
+
+ statusLabel = new QLabel(tr("Please enter the name of an FTP server."));
+#ifdef Q_OS_SYMBIAN
+ // Use word wrapping to fit the text on screen
+ statusLabel->setWordWrap( true );
+#endif
+
+ fileList = new QTreeWidget;
+ fileList->setEnabled(false);
+ fileList->setRootIsDecorated(false);
+ fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time"));
+ fileList->header()->setStretchLastSection(false);
+
+ connectButton = new QPushButton(tr("Connect"));
+ connectButton->setDefault(true);
+
+ cdToParentButton = new QPushButton;
+ cdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png"));
+ cdToParentButton->setEnabled(false);
+
+ downloadButton = new QPushButton(tr("Download"));
+ downloadButton->setEnabled(false);
+
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+
+ progressDialog = new QProgressDialog(this);
+
+ connect(fileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
+ this, SLOT(processItem(QTreeWidgetItem*,int)));
+ connect(fileList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
+ this, SLOT(enableDownloadButton()));
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
+ connect(connectButton, SIGNAL(clicked()), this, SLOT(connectOrDisconnect()));
+ connect(cdToParentButton, SIGNAL(clicked()), this, SLOT(cdToParent()));
+ connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *topLayout = new QHBoxLayout;
+ topLayout->addWidget(ftpServerLabel);
+ topLayout->addWidget(ftpServerLineEdit);
+#ifndef Q_OS_SYMBIAN
+ topLayout->addWidget(cdToParentButton);
+ topLayout->addWidget(connectButton);
+#else
+ // Make app better lookin on small screen
+ QHBoxLayout *topLayout2 = new QHBoxLayout;
+ topLayout2->addWidget(cdToParentButton);
+ topLayout2->addWidget(connectButton);
+#endif
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(topLayout);
+#ifdef Q_OS_SYMBIAN
+ // Make app better lookin on small screen
+ mainLayout->addLayout(topLayout2);
+#endif
+ mainLayout->addWidget(fileList);
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ QNetworkConfigurationManager manager;
+ if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
+ // Get saved network configuration
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
+ settings.endGroup();
+
+ // If the saved network configuration is not currently discovered use the system default
+ QNetworkConfiguration config = manager.configurationFromIdentifier(id);
+ if ((config.state() & QNetworkConfiguration::Discovered) !=
+ QNetworkConfiguration::Discovered) {
+ config = manager.defaultConfiguration();
+ }
+
+ networkSession = new QNetworkSession(config, this);
+ connect(networkSession, SIGNAL(opened()), this, SLOT(enableConnectButton()));
+
+ connectButton->setEnabled(false);
+ statusLabel->setText(tr("Opening network session."));
+ networkSession->open();
+ }
+
+ setWindowTitle(tr("FTP"));
+}
+
+QSize FtpWindow::sizeHint() const
+{
+ return QSize(500, 300);
+}
+
+//![0]
+void FtpWindow::connectOrDisconnect()
+{
+ if (ftp) {
+ ftp->abort();
+ ftp->deleteLater();
+ ftp = 0;
+//![0]
+ fileList->setEnabled(false);
+ cdToParentButton->setEnabled(false);
+ downloadButton->setEnabled(false);
+ connectButton->setEnabled(true);
+ connectButton->setText(tr("Connect"));
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::ArrowCursor);
+#endif
+ statusLabel->setText(tr("Please enter the name of an FTP server."));
+ return;
+ }
+
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::WaitCursor);
+#endif
+
+//![1]
+ ftp = new QFtp(this);
+ connect(ftp, SIGNAL(commandFinished(int,bool)),
+ this, SLOT(ftpCommandFinished(int,bool)));
+ connect(ftp, SIGNAL(listInfo(QUrlInfo)),
+ this, SLOT(addToList(QUrlInfo)));
+ connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
+ this, SLOT(updateDataTransferProgress(qint64,qint64)));
+
+ fileList->clear();
+ currentPath.clear();
+ isDirectory.clear();
+//![1]
+
+//![2]
+ QUrl url(ftpServerLineEdit->text());
+ if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
+ ftp->connectToHost(ftpServerLineEdit->text(), 21);
+ ftp->login();
+ } else {
+ ftp->connectToHost(url.host(), url.port(21));
+
+ if (!url.userName().isEmpty())
+ ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
+ else
+ ftp->login();
+ if (!url.path().isEmpty())
+ ftp->cd(url.path());
+ }
+//![2]
+
+ fileList->setEnabled(true);
+ connectButton->setEnabled(false);
+ connectButton->setText(tr("Disconnect"));
+ statusLabel->setText(tr("Connecting to FTP server %1...")
+ .arg(ftpServerLineEdit->text()));
+}
+
+//![3]
+void FtpWindow::downloadFile()
+{
+ QString fileName = fileList->currentItem()->text(0);
+//![3]
+//
+ if (QFile::exists(fileName)) {
+ QMessageBox::information(this, tr("FTP"),
+ tr("There already exists a file called %1 in "
+ "the current directory.")
+ .arg(fileName));
+ return;
+ }
+
+//![4]
+ file = new QFile(fileName);
+ if (!file->open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("FTP"),
+ tr("Unable to save the file %1: %2.")
+ .arg(fileName).arg(file->errorString()));
+ delete file;
+ return;
+ }
+
+ ftp->get(fileList->currentItem()->text(0), file);
+
+ progressDialog->setLabelText(tr("Downloading %1...").arg(fileName));
+ downloadButton->setEnabled(false);
+ progressDialog->exec();
+}
+//![4]
+
+//![5]
+void FtpWindow::cancelDownload()
+{
+ ftp->abort();
+}
+//![5]
+
+//![6]
+void FtpWindow::ftpCommandFinished(int, bool error)
+{
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::ArrowCursor);
+#endif
+
+ if (ftp->currentCommand() == QFtp::ConnectToHost) {
+ if (error) {
+ QMessageBox::information(this, tr("FTP"),
+ tr("Unable to connect to the FTP server "
+ "at %1. Please check that the host "
+ "name is correct.")
+ .arg(ftpServerLineEdit->text()));
+ connectOrDisconnect();
+ return;
+ }
+ statusLabel->setText(tr("Logged onto %1.")
+ .arg(ftpServerLineEdit->text()));
+ fileList->setFocus();
+ downloadButton->setDefault(true);
+ connectButton->setEnabled(true);
+ return;
+ }
+//![6]
+
+//![7]
+ if (ftp->currentCommand() == QFtp::Login)
+ ftp->list();
+//![7]
+
+//![8]
+ if (ftp->currentCommand() == QFtp::Get) {
+ if (error) {
+ statusLabel->setText(tr("Canceled download of %1.")
+ .arg(file->fileName()));
+ file->close();
+ file->remove();
+ } else {
+ statusLabel->setText(tr("Downloaded %1 to current directory.")
+ .arg(file->fileName()));
+ file->close();
+ }
+ delete file;
+ enableDownloadButton();
+ progressDialog->hide();
+//![8]
+//![9]
+ } else if (ftp->currentCommand() == QFtp::List) {
+ if (isDirectory.isEmpty()) {
+ fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr("<empty>")));
+ fileList->setEnabled(false);
+ }
+ }
+//![9]
+}
+
+//![10]
+void FtpWindow::addToList(const QUrlInfo &urlInfo)
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem;
+ item->setText(0, urlInfo.name());
+ item->setText(1, QString::number(urlInfo.size()));
+ item->setText(2, urlInfo.owner());
+ item->setText(3, urlInfo.group());
+ item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy"));
+
+ QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png");
+ item->setIcon(0, pixmap);
+
+ isDirectory[urlInfo.name()] = urlInfo.isDir();
+ fileList->addTopLevelItem(item);
+ if (!fileList->currentItem()) {
+ fileList->setCurrentItem(fileList->topLevelItem(0));
+ fileList->setEnabled(true);
+ }
+}
+//![10]
+
+//![11]
+void FtpWindow::processItem(QTreeWidgetItem *item, int /*column*/)
+{
+ QString name = item->text(0);
+ if (isDirectory.value(name)) {
+ fileList->clear();
+ isDirectory.clear();
+ currentPath += '/';
+ currentPath += name;
+ ftp->cd(name);
+ ftp->list();
+ cdToParentButton->setEnabled(true);
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::WaitCursor);
+#endif
+ return;
+ }
+}
+//![11]
+
+//![12]
+void FtpWindow::cdToParent()
+{
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::WaitCursor);
+#endif
+ fileList->clear();
+ isDirectory.clear();
+ currentPath = currentPath.left(currentPath.lastIndexOf('/'));
+ if (currentPath.isEmpty()) {
+ cdToParentButton->setEnabled(false);
+ ftp->cd("/");
+ } else {
+ ftp->cd(currentPath);
+ }
+ ftp->list();
+}
+//![12]
+
+//![13]
+void FtpWindow::updateDataTransferProgress(qint64 readBytes,
+ qint64 totalBytes)
+{
+ progressDialog->setMaximum(totalBytes);
+ progressDialog->setValue(readBytes);
+}
+//![13]
+
+//![14]
+void FtpWindow::enableDownloadButton()
+{
+ QTreeWidgetItem *current = fileList->currentItem();
+ if (current) {
+ QString currentFile = current->text(0);
+ downloadButton->setEnabled(!isDirectory.value(currentFile));
+ } else {
+ downloadButton->setEnabled(false);
+ }
+}
+//![14]
+
+void FtpWindow::enableConnectButton()
+{
+ // Save the used configuration
+ QNetworkConfiguration config = networkSession->configuration();
+ QString id;
+ if (config.type() == QNetworkConfiguration::UserChoice)
+ id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
+ else
+ id = config.identifier();
+
+ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
+ settings.beginGroup(QLatin1String("QtNetwork"));
+ settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
+ settings.endGroup();
+
+ connectButton->setEnabled(networkSession->isOpen());
+ statusLabel->setText(tr("Please enter the name of an FTP server."));
+}
+
diff --git a/examples/network/qftp/ftpwindow.h b/examples/network/qftp/ftpwindow.h
new file mode 100644
index 0000000000..a9df99d2b3
--- /dev/null
+++ b/examples/network/qftp/ftpwindow.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FTPWINDOW_H
+#define FTPWINDOW_H
+
+#include <QDialog>
+#include <QHash>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QFile;
+class QFtp;
+class QLabel;
+class QLineEdit;
+class QTreeWidget;
+class QTreeWidgetItem;
+class QProgressDialog;
+class QPushButton;
+class QUrlInfo;
+class QNetworkSession;
+QT_END_NAMESPACE
+
+class FtpWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FtpWindow(QWidget *parent = 0);
+ QSize sizeHint() const;
+
+//![0]
+private slots:
+ void connectOrDisconnect();
+ void downloadFile();
+ void cancelDownload();
+
+ void ftpCommandFinished(int commandId, bool error);
+ void addToList(const QUrlInfo &urlInfo);
+ void processItem(QTreeWidgetItem *item, int column);
+ void cdToParent();
+ void updateDataTransferProgress(qint64 readBytes,
+ qint64 totalBytes);
+ void enableDownloadButton();
+ void enableConnectButton();
+//![0]
+
+private:
+ QLabel *ftpServerLabel;
+ QLineEdit *ftpServerLineEdit;
+ QLabel *statusLabel;
+ QTreeWidget *fileList;
+ QPushButton *cdToParentButton;
+ QPushButton *connectButton;
+ QPushButton *downloadButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+ QProgressDialog *progressDialog;
+
+//![1]
+ QHash<QString, bool> isDirectory;
+ QString currentPath;
+ QFtp *ftp;
+ QFile *file;
+
+ QNetworkSession *networkSession;
+//![1]
+};
+
+#endif
diff --git a/examples/network/qftp/images/cdtoparent.png b/examples/network/qftp/images/cdtoparent.png
new file mode 100644
index 0000000000..24b6180829
--- /dev/null
+++ b/examples/network/qftp/images/cdtoparent.png
Binary files differ
diff --git a/examples/network/qftp/images/dir.png b/examples/network/qftp/images/dir.png
new file mode 100644
index 0000000000..0ce5ae75fc
--- /dev/null
+++ b/examples/network/qftp/images/dir.png
Binary files differ
diff --git a/examples/network/qftp/images/file.png b/examples/network/qftp/images/file.png
new file mode 100644
index 0000000000..be6c53089a
--- /dev/null
+++ b/examples/network/qftp/images/file.png
Binary files differ
diff --git a/examples/network/qftp/main.cpp b/examples/network/qftp/main.cpp
new file mode 100644
index 0000000000..f6eb2d4db2
--- /dev/null
+++ b/examples/network/qftp/main.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "ftpwindow.h"
+
+#ifdef Q_OS_SYMBIAN
+#include <QDir>
+#include <QDesktopWidget>
+#endif
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(ftp);
+#ifdef Q_OS_SYMBIAN
+ // Change current directory from default private to c:\data
+ // in order that user can access the downloaded content
+ QDir::setCurrent( "c:\\data" );
+#endif
+ QApplication app(argc, argv);
+ FtpWindow ftpWin;
+#ifdef Q_OS_SYMBIAN
+ // Make application better looking and more usable on small screen
+ ftpWin.showMaximized();
+#else
+ ftpWin.show();
+#endif
+ return ftpWin.exec();
+}
diff --git a/examples/network/qftp/qftp.pro b/examples/network/qftp/qftp.pro
new file mode 100644
index 0000000000..3f0f07ae30
--- /dev/null
+++ b/examples/network/qftp/qftp.pro
@@ -0,0 +1,18 @@
+HEADERS = ftpwindow.h
+SOURCES = ftpwindow.cpp \
+ main.cpp
+RESOURCES += ftp.qrc
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/qftp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/qftp
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A648
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE
+ TARGET.CAPABILITY="NetworkServices ReadUserData WriteUserData"
+}
diff --git a/examples/network/securesocketclient/certificateinfo.cpp b/examples/network/securesocketclient/certificateinfo.cpp
new file mode 100644
index 0000000000..ff3a4d2f3c
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "certificateinfo.h"
+#include "ui_certificateinfo.h"
+
+CertificateInfo::CertificateInfo(QWidget *parent)
+ : QDialog(parent)
+{
+ form = new Ui_CertificateInfo;
+ form->setupUi(this);
+
+ connect(form->certificationPathView, SIGNAL(currentRowChanged(int)),
+ this, SLOT(updateCertificateInfo(int)));
+}
+
+CertificateInfo::~CertificateInfo()
+{
+ delete form;
+}
+
+void CertificateInfo::setCertificateChain(const QList<QSslCertificate> &chain)
+{
+ this->chain = chain;
+
+ form->certificationPathView->clear();
+
+ for (int i = 0; i < chain.size(); ++i) {
+ const QSslCertificate &cert = chain.at(i);
+ form->certificationPathView->addItem(tr("%1%2 (%3)").arg(!i ? QString() : tr("Issued by: "))
+ .arg(cert.subjectInfo(QSslCertificate::Organization))
+ .arg(cert.subjectInfo(QSslCertificate::CommonName)));
+ }
+
+ form->certificationPathView->setCurrentRow(0);
+}
+
+void CertificateInfo::updateCertificateInfo(int index)
+{
+ form->certificateInfoView->clear();
+ if (index >= 0 && index < chain.size()) {
+ const QSslCertificate &cert = chain.at(index);
+ QStringList lines;
+ lines << tr("Organization: %1").arg(cert.subjectInfo(QSslCertificate::Organization))
+ << tr("Subunit: %1").arg(cert.subjectInfo(QSslCertificate::OrganizationalUnitName))
+ << tr("Country: %1").arg(cert.subjectInfo(QSslCertificate::CountryName))
+ << tr("Locality: %1").arg(cert.subjectInfo(QSslCertificate::LocalityName))
+ << tr("State/Province: %1").arg(cert.subjectInfo(QSslCertificate::StateOrProvinceName))
+ << tr("Common Name: %1").arg(cert.subjectInfo(QSslCertificate::CommonName))
+ << QString()
+ << tr("Issuer Organization: %1").arg(cert.issuerInfo(QSslCertificate::Organization))
+ << tr("Issuer Unit Name: %1").arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName))
+ << tr("Issuer Country: %1").arg(cert.issuerInfo(QSslCertificate::CountryName))
+ << tr("Issuer Locality: %1").arg(cert.issuerInfo(QSslCertificate::LocalityName))
+ << tr("Issuer State/Province: %1").arg(cert.issuerInfo(QSslCertificate::StateOrProvinceName))
+ << tr("Issuer Common Name: %1").arg(cert.issuerInfo(QSslCertificate::CommonName));
+ foreach (QString line, lines)
+ form->certificateInfoView->addItem(line);
+ } else {
+ form->certificateInfoView->clear();
+ }
+}
diff --git a/examples/network/securesocketclient/certificateinfo.h b/examples/network/securesocketclient/certificateinfo.h
new file mode 100644
index 0000000000..6e60ade4f0
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CERTIFICATEINFO_H
+#define CERTIFICATEINFO_H
+
+#include <QtGui/QDialog>
+#include <QtNetwork/QSslCertificate>
+
+QT_BEGIN_NAMESPACE
+class Ui_CertificateInfo;
+QT_END_NAMESPACE
+
+class CertificateInfo : public QDialog
+{
+ Q_OBJECT
+public:
+ CertificateInfo(QWidget *parent = 0);
+ ~CertificateInfo();
+
+ void setCertificateChain(const QList<QSslCertificate> &chain);
+
+private slots:
+ void updateCertificateInfo(int index);
+
+private:
+ Ui_CertificateInfo *form;
+ QList<QSslCertificate> chain;
+};
+
+#endif
diff --git a/examples/network/securesocketclient/certificateinfo.ui b/examples/network/securesocketclient/certificateinfo.ui
new file mode 100644
index 0000000000..3761fe8f50
--- /dev/null
+++ b/examples/network/securesocketclient/certificateinfo.ui
@@ -0,0 +1,85 @@
+<ui version="4.0" >
+ <class>CertificateInfo</class>
+ <widget class="QDialog" name="CertificateInfo" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>397</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Display Certificate Information</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>Certification Path</string>
+ </property>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QListWidget" name="certificationPathView" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="title" >
+ <string>Certificate Information</string>
+ </property>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QListWidget" name="certificateInfoView" />
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>clicked(QAbstractButton*)</signal>
+ <receiver>CertificateInfo</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>343</x>
+ <y>374</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>352</x>
+ <y>422</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/network/securesocketclient/encrypted.png b/examples/network/securesocketclient/encrypted.png
new file mode 100644
index 0000000000..04a05c1cb1
--- /dev/null
+++ b/examples/network/securesocketclient/encrypted.png
Binary files differ
diff --git a/examples/network/securesocketclient/main.cpp b/examples/network/securesocketclient/main.cpp
new file mode 100644
index 0000000000..c15534b523
--- /dev/null
+++ b/examples/network/securesocketclient/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+
+#include "sslclient.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(securesocketclient);
+
+ QApplication app(argc, argv);
+
+ if (!QSslSocket::supportsSsl()) {
+ QMessageBox::information(0, "Secure Socket Client",
+ "This system does not support OpenSSL.");
+ return -1;
+ }
+
+ SslClient client;
+ client.show();
+
+ return app.exec();
+}
diff --git a/examples/network/securesocketclient/securesocketclient.pro b/examples/network/securesocketclient/securesocketclient.pro
new file mode 100644
index 0000000000..3bbd9a81df
--- /dev/null
+++ b/examples/network/securesocketclient/securesocketclient.pro
@@ -0,0 +1,21 @@
+HEADERS += certificateinfo.h \
+ sslclient.h
+SOURCES += certificateinfo.cpp \
+ main.cpp \
+ sslclient.cpp
+RESOURCES += securesocketclient.qrc
+FORMS += certificateinfo.ui \
+ sslclient.ui \
+ sslerrors.ui
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/securesocketclient
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/securesocketclient
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000CF67
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/network/securesocketclient/securesocketclient.qrc b/examples/network/securesocketclient/securesocketclient.qrc
new file mode 100644
index 0000000000..83b49c790c
--- /dev/null
+++ b/examples/network/securesocketclient/securesocketclient.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>encrypted.png</file>
+</qresource>
+</RCC>
diff --git a/examples/network/securesocketclient/sslclient.cpp b/examples/network/securesocketclient/sslclient.cpp
new file mode 100644
index 0000000000..43b81cd984
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "certificateinfo.h"
+#include "sslclient.h"
+#include "ui_sslclient.h"
+#include "ui_sslerrors.h"
+
+#include <QtGui/QScrollBar>
+#include <QtGui/QStyle>
+#include <QtGui/QToolButton>
+#include <QtNetwork/QSslCipher>
+
+SslClient::SslClient(QWidget *parent)
+ : QWidget(parent), socket(0), padLock(0), executingDialog(false)
+{
+ form = new Ui_Form;
+ form->setupUi(this);
+ form->hostNameEdit->setSelection(0, form->hostNameEdit->text().size());
+ form->sessionOutput->setHtml(tr("&lt;not connected&gt;"));
+
+ connect(form->hostNameEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(updateEnabledState()));
+ connect(form->connectButton, SIGNAL(clicked()),
+ this, SLOT(secureConnect()));
+ connect(form->sendButton, SIGNAL(clicked()),
+ this, SLOT(sendData()));
+}
+
+SslClient::~SslClient()
+{
+ delete form;
+}
+
+void SslClient::updateEnabledState()
+{
+ bool unconnected = !socket || socket->state() == QAbstractSocket::UnconnectedState;
+
+ form->hostNameEdit->setReadOnly(!unconnected);
+ form->hostNameEdit->setFocusPolicy(unconnected ? Qt::StrongFocus : Qt::NoFocus);
+
+ form->hostNameLabel->setEnabled(unconnected);
+ form->portBox->setEnabled(unconnected);
+ form->portLabel->setEnabled(unconnected);
+ form->connectButton->setEnabled(unconnected && !form->hostNameEdit->text().isEmpty());
+
+ bool connected = socket && socket->state() == QAbstractSocket::ConnectedState;
+ form->sessionBox->setEnabled(connected);
+ form->sessionOutput->setEnabled(connected);
+ form->sessionInput->setEnabled(connected);
+ form->sessionInputLabel->setEnabled(connected);
+ form->sendButton->setEnabled(connected);
+}
+
+void SslClient::secureConnect()
+{
+ if (!socket) {
+ socket = new QSslSocket(this);
+ connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+ this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+ connect(socket, SIGNAL(encrypted()),
+ this, SLOT(socketEncrypted()));
+ connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
+ this, SLOT(sslErrors(QList<QSslError>)));
+ connect(socket, SIGNAL(readyRead()),
+ this, SLOT(socketReadyRead()));
+ }
+
+ socket->connectToHostEncrypted(form->hostNameEdit->text(), form->portBox->value());
+ updateEnabledState();
+}
+
+void SslClient::socketStateChanged(QAbstractSocket::SocketState state)
+{
+ if (executingDialog)
+ return;
+
+ updateEnabledState();
+ if (state == QAbstractSocket::UnconnectedState) {
+ form->hostNameEdit->setPalette(QPalette());
+ form->hostNameEdit->setFocus();
+ form->cipherLabel->setText(tr("<none>"));
+ if (padLock)
+ padLock->hide();
+ socket->deleteLater();
+ socket = 0;
+ }
+}
+
+void SslClient::socketEncrypted()
+{
+ if (!socket)
+ return; // might have disconnected already
+
+ form->sessionOutput->clear();
+ form->sessionInput->setFocus();
+
+ QPalette palette;
+ palette.setColor(QPalette::Base, QColor(255, 255, 192));
+ form->hostNameEdit->setPalette(palette);
+
+ QSslCipher ciph = socket->sessionCipher();
+ QString cipher = QString("%1, %2 (%3/%4)").arg(ciph.authenticationMethod())
+ .arg(ciph.name()).arg(ciph.usedBits()).arg(ciph.supportedBits());;
+ form->cipherLabel->setText(cipher);
+
+ if (!padLock) {
+ padLock = new QToolButton;
+ padLock->setIcon(QIcon(":/encrypted.png"));
+#ifndef QT_NO_CURSOR
+ padLock->setCursor(Qt::ArrowCursor);
+#endif
+ padLock->setToolTip(tr("Display encryption details."));
+
+ int extent = form->hostNameEdit->height() - 2;
+ padLock->resize(extent, extent);
+ padLock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
+
+ QHBoxLayout *layout = new QHBoxLayout(form->hostNameEdit);
+ layout->setMargin(form->hostNameEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth));
+ layout->setSpacing(0);
+ layout->addStretch();
+ layout->addWidget(padLock);
+
+ form->hostNameEdit->setLayout(layout);
+
+ connect(padLock, SIGNAL(clicked()),
+ this, SLOT(displayCertificateInfo()));
+ } else {
+ padLock->show();
+ }
+}
+
+void SslClient::socketReadyRead()
+{
+ appendString(QString::fromUtf8(socket->readAll()));
+}
+
+void SslClient::sendData()
+{
+ QString input = form->sessionInput->text();
+ appendString(input + '\n');
+ socket->write(input.toUtf8() + "\r\n");
+ form->sessionInput->clear();
+}
+
+void SslClient::sslErrors(const QList<QSslError> &errors)
+{
+ QDialog errorDialog(this);
+ Ui_SslErrors ui;
+ ui.setupUi(&errorDialog);
+ connect(ui.certificateChainButton, SIGNAL(clicked()),
+ this, SLOT(displayCertificateInfo()));
+
+ foreach (const QSslError &error, errors)
+ ui.sslErrorList->addItem(error.errorString());
+
+ executingDialog = true;
+ if (errorDialog.exec() == QDialog::Accepted)
+ socket->ignoreSslErrors();
+ executingDialog = false;
+
+ // did the socket state change?
+ if (socket->state() != QAbstractSocket::ConnectedState)
+ socketStateChanged(socket->state());
+}
+
+void SslClient::displayCertificateInfo()
+{
+ CertificateInfo *info = new CertificateInfo(this);
+ info->setCertificateChain(socket->peerCertificateChain());
+ info->exec();
+ info->deleteLater();
+}
+
+void SslClient::appendString(const QString &line)
+{
+ QTextCursor cursor(form->sessionOutput->textCursor());
+ cursor.movePosition(QTextCursor::End);
+ cursor.insertText(line);
+ form->sessionOutput->verticalScrollBar()->setValue(form->sessionOutput->verticalScrollBar()->maximum());
+}
diff --git a/examples/network/securesocketclient/sslclient.h b/examples/network/securesocketclient/sslclient.h
new file mode 100644
index 0000000000..33a9a882b6
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SSLCLIENT_H
+#define SSLCLIENT_H
+
+#include <QtGui/QWidget>
+#include <QtNetwork/QAbstractSocket>
+#include <QtNetwork/QSslSocket>
+
+QT_BEGIN_NAMESPACE
+class QSslSocket;
+class QToolButton;
+class Ui_Form;
+QT_END_NAMESPACE
+
+class SslClient : public QWidget
+{
+ Q_OBJECT
+public:
+ SslClient(QWidget *parent = 0);
+ ~SslClient();
+
+private slots:
+ void updateEnabledState();
+ void secureConnect();
+ void socketStateChanged(QAbstractSocket::SocketState state);
+ void socketEncrypted();
+ void socketReadyRead();
+ void sendData();
+ void sslErrors(const QList<QSslError> &errors);
+ void displayCertificateInfo();
+
+private:
+ void appendString(const QString &line);
+
+ QSslSocket *socket;
+ QToolButton *padLock;
+ Ui_Form *form;
+ bool executingDialog;
+};
+
+#endif
diff --git a/examples/network/securesocketclient/sslclient.ui b/examples/network/securesocketclient/sslclient.ui
new file mode 100644
index 0000000000..5a24751168
--- /dev/null
+++ b/examples/network/securesocketclient/sslclient.ui
@@ -0,0 +1,190 @@
+<ui version="4.0" >
+ <class>Form</class>
+ <widget class="QWidget" name="Form" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>343</width>
+ <height>320</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Secure Socket Client</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="hostNameLabel" >
+ <property name="text" >
+ <string>Host name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="hostNameEdit" >
+ <property name="text" >
+ <string>imap.example.com</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="portLabel" >
+ <property name="text" >
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QSpinBox" name="portBox" >
+ <property name="minimum" >
+ <number>1</number>
+ </property>
+ <property name="maximum" >
+ <number>65535</number>
+ </property>
+ <property name="value" >
+ <number>993</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QPushButton" name="connectButton" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="text" >
+ <string>Connect to host</string>
+ </property>
+ <property name="default" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="sessionBox" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="title" >
+ <string>Active session</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="cipherText" >
+ <property name="text" >
+ <string>Cryptographic Cipher:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="cipherLabel" >
+ <property name="text" >
+ <string>&lt;none></string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="sessionOutput" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="focusPolicy" >
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;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;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QLabel" name="sessionInputLabel" >
+ <property name="text" >
+ <string>Input:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="sessionInput" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="sendButton" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="focusPolicy" >
+ <enum>Qt::TabFocus</enum>
+ </property>
+ <property name="text" >
+ <string>&amp;Send</string>
+ </property>
+ <property name="default" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>hostNameEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>connectButton</receiver>
+ <slot>animateClick()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>126</x>
+ <y>20</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>142</x>
+ <y>78</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>sessionInput</sender>
+ <signal>returnPressed()</signal>
+ <receiver>sendButton</receiver>
+ <slot>animateClick()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>142</x>
+ <y>241</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>297</x>
+ <y>234</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/network/securesocketclient/sslerrors.ui b/examples/network/securesocketclient/sslerrors.ui
new file mode 100644
index 0000000000..4aac18cddb
--- /dev/null
+++ b/examples/network/securesocketclient/sslerrors.ui
@@ -0,0 +1,110 @@
+<ui version="4.0" >
+ <class>SslErrors</class>
+ <widget class="QDialog" name="SslErrors" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>371</width>
+ <height>216</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Unable To Validate The Connection</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-weight:600; color:#ff0000;">Warning&lt;/span>&lt;span style=" color:#ff0000;">:&lt;/span>&lt;span style=" color:#000000;"> One or more errors with this connection prevent validating the authenticity of the host you are connecting to. Please review the following list of errors, and click &lt;/span>&lt;span style=" color:#000000;">Ignore&lt;/span>&lt;span style=" color:#000000;"> to continue, or &lt;/span>&lt;span style=" color:#000000;">Cancel&lt;/span>&lt;span style=" color:#000000;"> to abort the connection.&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="wordWrap" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="sslErrorList" />
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QPushButton" name="certificateChainButton" >
+ <property name="text" >
+ <string>View Certificate Chain</string>
+ </property>
+ <property name="autoDefault" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton" >
+ <property name="text" >
+ <string>Ignore</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton_2" >
+ <property name="text" >
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>pushButton</sender>
+ <signal>clicked()</signal>
+ <receiver>SslErrors</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>235</x>
+ <y>185</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>228</x>
+ <y>287</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>pushButton_2</sender>
+ <signal>clicked()</signal>
+ <receiver>SslErrors</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>325</x>
+ <y>192</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>333</x>
+ <y>231</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/network/threadedfortuneserver/dialog.cpp b/examples/network/threadedfortuneserver/dialog.cpp
new file mode 100644
index 0000000000..b69f42cc85
--- /dev/null
+++ b/examples/network/threadedfortuneserver/dialog.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtNetwork>
+
+#include <stdlib.h>
+
+#include "dialog.h"
+#include "fortuneserver.h"
+
+Dialog::Dialog(QWidget *parent)
+ : QDialog(parent)
+{
+ statusLabel = new QLabel;
+ quitButton = new QPushButton(tr("Quit"));
+ quitButton->setAutoDefault(false);
+
+ if (!server.listen()) {
+ QMessageBox::critical(this, tr("Threaded Fortune Server"),
+ tr("Unable to start the server: %1.")
+ .arg(server.errorString()));
+ close();
+ return;
+ }
+
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address()) {
+ ipAddress = ipAddressesList.at(i).toString();
+ break;
+ }
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+ statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"
+ "Run the Fortune Client example now.")
+ .arg(ipAddress).arg(server.serverPort()));
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch(1);
+ buttonLayout->addWidget(quitButton);
+ buttonLayout->addStretch(1);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(statusLabel);
+ mainLayout->addLayout(buttonLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Threaded Fortune Server"));
+}
diff --git a/examples/network/threadedfortuneserver/dialog.h b/examples/network/threadedfortuneserver/dialog.h
new file mode 100644
index 0000000000..10ae3ebaa2
--- /dev/null
+++ b/examples/network/threadedfortuneserver/dialog.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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>
+#include "fortuneserver.h"
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+QT_END_NAMESPACE
+
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog(QWidget *parent = 0);
+
+private:
+ QLabel *statusLabel;
+ QPushButton *quitButton;
+ FortuneServer server;
+};
+
+#endif
diff --git a/examples/network/threadedfortuneserver/fortuneserver.cpp b/examples/network/threadedfortuneserver/fortuneserver.cpp
new file mode 100644
index 0000000000..7179ba51e8
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortuneserver.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fortuneserver.h"
+#include "fortunethread.h"
+
+#include <stdlib.h>
+
+//! [0]
+FortuneServer::FortuneServer(QObject *parent)
+ : QTcpServer(parent)
+{
+ fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
+ << tr("You've got to think about tomorrow.")
+ << tr("You will be surprised by a loud noise.")
+ << tr("You will feel hungry again in another hour.")
+ << tr("You might have mail.")
+ << tr("You cannot kill time without injuring eternity.")
+ << tr("Computers are not intelligent. They only think they are.");
+}
+//! [0]
+
+//! [1]
+void FortuneServer::incomingConnection(int socketDescriptor)
+{
+ QString fortune = fortunes.at(qrand() % fortunes.size());
+ FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
+ connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+ thread->start();
+}
+//! [1]
diff --git a/examples/network/threadedfortuneserver/fortuneserver.h b/examples/network/threadedfortuneserver/fortuneserver.h
new file mode 100644
index 0000000000..785a72e27e
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortuneserver.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FORTUNESERVER_H
+#define FORTUNESERVER_H
+
+#include <QStringList>
+#include <QTcpServer>
+
+//! [0]
+class FortuneServer : public QTcpServer
+{
+ Q_OBJECT
+
+public:
+ FortuneServer(QObject *parent = 0);
+
+protected:
+ void incomingConnection(int socketDescriptor);
+
+private:
+ QStringList fortunes;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/threadedfortuneserver/fortunethread.cpp b/examples/network/threadedfortuneserver/fortunethread.cpp
new file mode 100644
index 0000000000..e9878e06d7
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortunethread.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fortunethread.h"
+
+#include <QtNetwork>
+
+//! [0]
+FortuneThread::FortuneThread(int socketDescriptor, const QString &fortune, QObject *parent)
+ : QThread(parent), socketDescriptor(socketDescriptor), text(fortune)
+{
+}
+//! [0]
+
+//! [1]
+void FortuneThread::run()
+{
+ QTcpSocket tcpSocket;
+//! [1] //! [2]
+ if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
+ emit error(tcpSocket.error());
+ return;
+ }
+//! [2] //! [3]
+
+ QByteArray block;
+ QDataStream out(&block, QIODevice::WriteOnly);
+ out.setVersion(QDataStream::Qt_4_0);
+ out << (quint16)0;
+ out << text;
+ out.device()->seek(0);
+ out << (quint16)(block.size() - sizeof(quint16));
+//! [3] //! [4]
+
+ tcpSocket.write(block);
+ tcpSocket.disconnectFromHost();
+ tcpSocket.waitForDisconnected();
+}
+//! [4]
diff --git a/examples/network/threadedfortuneserver/fortunethread.h b/examples/network/threadedfortuneserver/fortunethread.h
new file mode 100644
index 0000000000..1d6f5608d8
--- /dev/null
+++ b/examples/network/threadedfortuneserver/fortunethread.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FORTUNETHREAD_H
+#define FORTUNETHREAD_H
+
+#include <QThread>
+#include <QTcpSocket>
+
+//! [0]
+class FortuneThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ FortuneThread(int socketDescriptor, const QString &fortune, QObject *parent);
+
+ void run();
+
+signals:
+ void error(QTcpSocket::SocketError socketError);
+
+private:
+ int socketDescriptor;
+ QString text;
+};
+//! [0]
+
+#endif
diff --git a/examples/network/threadedfortuneserver/main.cpp b/examples/network/threadedfortuneserver/main.cpp
new file mode 100644
index 0000000000..396f9244b6
--- /dev/null
+++ b/examples/network/threadedfortuneserver/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QtCore>
+
+#include <stdlib.h>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Dialog dialog;
+ dialog.show();
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ return dialog.exec();
+}
diff --git a/examples/network/threadedfortuneserver/threadedfortuneserver.pro b/examples/network/threadedfortuneserver/threadedfortuneserver.pro
new file mode 100644
index 0000000000..c053c36afe
--- /dev/null
+++ b/examples/network/threadedfortuneserver/threadedfortuneserver.pro
@@ -0,0 +1,16 @@
+HEADERS = dialog.h \
+ fortuneserver.h \
+ fortunethread.h
+SOURCES = dialog.cpp \
+ fortuneserver.cpp \
+ fortunethread.cpp \
+ main.cpp
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/threadedfortuneserver
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS threadedfortuneserver.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/threadedfortuneserver
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/torrent/addtorrentdialog.cpp b/examples/network/torrent/addtorrentdialog.cpp
new file mode 100644
index 0000000000..c78535a309
--- /dev/null
+++ b/examples/network/torrent/addtorrentdialog.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "addtorrentdialog.h"
+#include "metainfo.h"
+
+#include <QFile>
+#include <QFileDialog>
+#include <QLineEdit>
+#include <QMetaObject>
+
+static QString stringNumber(qint64 number)
+{
+ QString tmp;
+ if (number > (1024 * 1024 * 1024))
+ tmp.sprintf("%.2fGB", number / (1024.0 * 1024.0 * 1024.0));
+ else if (number > (1024 * 1024))
+ tmp.sprintf("%.2fMB", number / (1024.0 * 1024.0));
+ else if (number > (1024))
+ tmp.sprintf("%.2fKB", number / (1024.0));
+ else
+ tmp.sprintf("%d bytes", int(number));
+ return tmp;
+}
+
+AddTorrentDialog::AddTorrentDialog(QWidget *parent)
+ : QDialog(parent, Qt::Sheet)
+{
+ ui.setupUi(this);
+
+ connect(ui.browseTorrents, SIGNAL(clicked()),
+ this, SLOT(selectTorrent()));
+ connect(ui.browseDestination, SIGNAL(clicked()),
+ this, SLOT(selectDestination()));
+ connect(ui.torrentFile, SIGNAL(textChanged(QString)),
+ this, SLOT(setTorrent(QString)));
+
+ ui.destinationFolder->setText(destinationDirectory = QDir::current().path());
+ ui.torrentFile->setFocus();
+}
+
+void AddTorrentDialog::selectTorrent()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a torrent file"),
+ lastDirectory,
+ tr("Torrents (*.torrent);; All files (*.*)"));
+ if (fileName.isEmpty())
+ return;
+ lastDirectory = QFileInfo(fileName).absolutePath();
+ setTorrent(fileName);
+}
+
+void AddTorrentDialog::selectDestination()
+{
+ QString dir = QFileDialog::getExistingDirectory(this, tr("Choose a destination directory"),
+ lastDestinationDirectory);
+ if (dir.isEmpty())
+ return;
+ lastDestinationDirectory = destinationDirectory = dir;
+ ui.destinationFolder->setText(destinationDirectory);
+ enableOkButton();
+}
+
+void AddTorrentDialog::enableOkButton()
+{
+ ui.okButton->setEnabled(!ui.destinationFolder->text().isEmpty()
+ && !ui.torrentFile->text().isEmpty());
+}
+
+void AddTorrentDialog::setTorrent(const QString &torrentFile)
+{
+ if (torrentFile.isEmpty()) {
+ enableOkButton();
+ return;
+ }
+
+ ui.torrentFile->setText(torrentFile);
+ if (!torrentFile.isEmpty())
+ lastDirectory = QFileInfo(torrentFile).absolutePath();
+
+ if (lastDestinationDirectory.isEmpty())
+ lastDestinationDirectory = lastDirectory;
+
+ MetaInfo metaInfo;
+ QFile torrent(torrentFile);
+ if (!torrent.open(QFile::ReadOnly) || !metaInfo.parse(torrent.readAll())) {
+ enableOkButton();
+ return;
+ }
+
+ ui.torrentFile->setText(torrentFile);
+ ui.announceUrl->setText(metaInfo.announceUrl());
+ if (metaInfo.comment().isEmpty())
+ ui.commentLabel->setText("<unknown>");
+ else
+ ui.commentLabel->setText(metaInfo.comment());
+ if (metaInfo.createdBy().isEmpty())
+ ui.creatorLabel->setText("<unknown>");
+ else
+ ui.creatorLabel->setText(metaInfo.createdBy());
+ ui.sizeLabel->setText(stringNumber(metaInfo.totalSize()));
+ if (metaInfo.fileForm() == MetaInfo::SingleFileForm) {
+ ui.torrentContents->setHtml(metaInfo.singleFile().name);
+ } else {
+ QString html;
+ foreach (MetaInfoMultiFile file, metaInfo.multiFiles()) {
+ QString name = metaInfo.name();
+ if (!name.isEmpty()) {
+ html += name;
+ if (!name.endsWith('/'))
+ html += '/';
+ }
+ html += file.path + "<br>";
+ }
+ ui.torrentContents->setHtml(html);
+ }
+
+ QFileInfo info(torrentFile);
+ ui.destinationFolder->setText(info.absolutePath());
+
+ enableOkButton();
+}
+
+QString AddTorrentDialog::torrentFileName() const
+{
+ return ui.torrentFile->text();
+}
+
+QString AddTorrentDialog::destinationFolder() const
+{
+ return ui.destinationFolder->text();
+}
diff --git a/examples/network/torrent/addtorrentdialog.h b/examples/network/torrent/addtorrentdialog.h
new file mode 100644
index 0000000000..09aa48c354
--- /dev/null
+++ b/examples/network/torrent/addtorrentdialog.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDTORRENTDIALOG_H
+#define ADDTORRENTDIALOG_H
+
+#include <QDialog>
+
+#include "ui_addtorrentform.h"
+
+class AddTorrentDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ AddTorrentDialog(QWidget *parent = 0);
+
+ QString torrentFileName() const;
+ QString destinationFolder() const;
+
+public slots:
+ void setTorrent(const QString &torrentFile);
+
+private slots:
+ void selectTorrent();
+ void selectDestination();
+ void enableOkButton();
+
+private:
+ Ui_AddTorrentFile ui;
+ QString destinationDirectory;
+ QString lastDirectory;
+ QString lastDestinationDirectory;
+};
+
+#endif
diff --git a/examples/network/torrent/bencodeparser.cpp b/examples/network/torrent/bencodeparser.cpp
new file mode 100644
index 0000000000..edb04c6d6b
--- /dev/null
+++ b/examples/network/torrent/bencodeparser.cpp
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "bencodeparser.h"
+
+#include <QList>
+#include <QMetaType>
+
+BencodeParser::BencodeParser()
+{
+}
+
+bool BencodeParser::parse(const QByteArray &content)
+{
+ if (content.isEmpty()) {
+ errString = QString("No content");
+ return false;
+ }
+
+ this->content = content;
+ index = 0;
+ infoStart = 0;
+ infoLength = 0;
+ return getDictionary(&dictionaryValue);
+}
+
+QString BencodeParser::errorString() const
+{
+ return errString;
+}
+
+QMap<QByteArray, QVariant> BencodeParser::dictionary() const
+{
+ return dictionaryValue;
+}
+
+QByteArray BencodeParser::infoSection() const
+{
+ return content.mid(infoStart, infoLength);
+}
+
+bool BencodeParser::getByteString(QByteArray *byteString)
+{
+ const int contentSize = content.size();
+ int size = -1;
+ do {
+ char c = content.at(index);
+ if (c < '0' || c > '9') {
+ if (size == -1)
+ return false;
+ if (c != ':') {
+ errString = QString("Unexpected character at pos %1: %2")
+ .arg(index).arg(c);
+ return false;
+ }
+ ++index;
+ break;
+ }
+ if (size == -1)
+ size = 0;
+ size *= 10;
+ size += c - '0';
+ } while (++index < contentSize);
+
+ if (byteString)
+ *byteString = content.mid(index, size);
+ index += size;
+ return true;
+}
+
+bool BencodeParser::getInteger(qint64 *integer)
+{
+ const int contentSize = content.size();
+ if (content.at(index) != 'i')
+ return false;
+
+ ++index;
+ qint64 num = -1;
+ bool negative = false;
+
+ do {
+ char c = content.at(index);
+ if (c < '0' || c > '9') {
+ if (num == -1) {
+ if (c != '-' || negative)
+ return false;
+ negative = true;
+ continue;
+ } else {
+ if (c != 'e') {
+ errString = QString("Unexpected character at pos %1: %2")
+ .arg(index).arg(c);
+ return false;
+ }
+ ++index;
+ break;
+ }
+ }
+ if (num == -1)
+ num = 0;
+ num *= 10;
+ num += c - '0';
+ } while (++index < contentSize);
+
+ if (integer)
+ *integer = negative ? -num : num;
+ return true;
+}
+
+bool BencodeParser::getList(QList<QVariant> *list)
+{
+ const int contentSize = content.size();
+ if (content.at(index) != 'l')
+ return false;
+
+ QList<QVariant> tmp;
+ ++index;
+
+ do {
+ if (content.at(index) == 'e') {
+ ++index;
+ break;
+ }
+
+ qint64 number;
+ QByteArray byteString;
+ QList<QVariant> tmpList;
+ QMap<QByteArray, QVariant> dictionary;
+
+ if (getInteger(&number))
+ tmp << number;
+ else if (getByteString(&byteString))
+ tmp << byteString;
+ else if (getList(&tmpList))
+ tmp << tmpList;
+ else if (getDictionary(&dictionary))
+ tmp << QVariant::fromValue<QMap<QByteArray, QVariant> >(dictionary);
+ else {
+ errString = QString("error at index %1").arg(index);
+ return false;
+ }
+ } while (index < contentSize);
+
+ if (list)
+ *list = tmp;
+ return true;
+}
+
+bool BencodeParser::getDictionary(QMap<QByteArray, QVariant> *dictionary)
+{
+ const int contentSize = content.size();
+ if (content.at(index) != 'd')
+ return false;
+
+ QMap<QByteArray, QVariant> tmp;
+ ++index;
+
+ do {
+ if (content.at(index) == 'e') {
+ ++index;
+ break;
+ }
+
+ QByteArray key;
+ if (!getByteString(&key))
+ break;
+
+ if (key == "info")
+ infoStart = index;
+
+ qint64 number;
+ QByteArray byteString;
+ QList<QVariant> tmpList;
+ QMap<QByteArray, QVariant> dictionary;
+
+ if (getInteger(&number))
+ tmp.insert(key, number);
+ else if (getByteString(&byteString))
+ tmp.insert(key, byteString);
+ else if (getList(&tmpList))
+ tmp.insert(key, tmpList);
+ else if (getDictionary(&dictionary))
+ tmp.insert(key, QVariant::fromValue<QMap<QByteArray, QVariant> >(dictionary));
+ else {
+ errString = QString("error at index %1").arg(index);
+ return false;
+ }
+
+ if (key == "info")
+ infoLength = index - infoStart;
+
+ } while (index < contentSize);
+
+ if (dictionary)
+ *dictionary = tmp;
+ return true;
+}
diff --git a/examples/network/torrent/bencodeparser.h b/examples/network/torrent/bencodeparser.h
new file mode 100644
index 0000000000..de8b8ffd93
--- /dev/null
+++ b/examples/network/torrent/bencodeparser.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BENCODEPARSER_H
+#define BENCODEPARSER_H
+
+#include <QByteArray>
+#include <QMap>
+#include <QString>
+#include <QVariant>
+#include <QList>
+
+typedef QMap<QByteArray,QVariant> Dictionary;
+Q_DECLARE_METATYPE(Dictionary)
+
+class BencodeParser
+{
+public:
+ BencodeParser();
+
+ bool parse(const QByteArray &content);
+ QString errorString() const;
+
+ QMap<QByteArray, QVariant> dictionary() const;
+ QByteArray infoSection() const;
+
+private:
+ bool getByteString(QByteArray *byteString);
+ bool getInteger(qint64 *integer);
+ bool getList(QList<QVariant> *list);
+ bool getDictionary(QMap<QByteArray, QVariant> *dictionary);
+
+ QMap<QByteArray, QVariant> dictionaryValue;
+
+ QString errString;
+ QByteArray content;
+ int index;
+
+ int infoStart;
+ int infoLength;
+};
+
+#endif
diff --git a/examples/network/torrent/connectionmanager.cpp b/examples/network/torrent/connectionmanager.cpp
new file mode 100644
index 0000000000..889933ea83
--- /dev/null
+++ b/examples/network/torrent/connectionmanager.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "connectionmanager.h"
+
+#include <QByteArray>
+#include <QDateTime>
+
+static const int MaxConnections = 250;
+
+Q_GLOBAL_STATIC(ConnectionManager, connectionManager)
+
+ConnectionManager *ConnectionManager::instance()
+{
+ return connectionManager();
+}
+
+bool ConnectionManager::canAddConnection() const
+{
+ return (connections.size() < MaxConnections);
+}
+
+void ConnectionManager::addConnection(PeerWireClient *client)
+{
+ connections << client;
+}
+
+void ConnectionManager::removeConnection(PeerWireClient *client)
+{
+ connections.remove(client);
+}
+
+int ConnectionManager::maxConnections() const
+{
+ return MaxConnections;
+}
+
+QByteArray ConnectionManager::clientId() const
+{
+ if (id.isEmpty()) {
+ // Generate peer id
+ int startupTime = int(QDateTime::currentDateTime().toTime_t());
+
+ QString s;
+ s.sprintf("-QT%04x-", (QT_VERSION % 0xffff00) >> 8);
+ id += s.toLatin1();
+ id += QByteArray::number(startupTime, 10);
+ id += QByteArray(20 - id.size(), '-');
+ }
+ return id;
+}
diff --git a/examples/network/torrent/connectionmanager.h b/examples/network/torrent/connectionmanager.h
new file mode 100644
index 0000000000..ef38507e45
--- /dev/null
+++ b/examples/network/torrent/connectionmanager.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 CONNECTIONMANAGER_H
+#define CONNECTIONMANAGER_H
+
+class PeerWireClient;
+
+#include <QByteArray>
+#include <QSet>
+
+class ConnectionManager
+{
+public:
+ static ConnectionManager *instance();
+
+ bool canAddConnection() const;
+ void addConnection(PeerWireClient *connection);
+ void removeConnection(PeerWireClient *connection);
+ int maxConnections() const;
+ QByteArray clientId() const;
+
+ private:
+ QSet<PeerWireClient *> connections;
+ mutable QByteArray id;
+};
+
+#endif
diff --git a/examples/network/torrent/filemanager.cpp b/examples/network/torrent/filemanager.cpp
new file mode 100644
index 0000000000..b4dfb25bca
--- /dev/null
+++ b/examples/network/torrent/filemanager.cpp
@@ -0,0 +1,446 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "filemanager.h"
+#include "metainfo.h"
+
+#include <QByteArray>
+#include <QDir>
+#include <QFile>
+#include <QTimer>
+#include <QTimerEvent>
+#include <QCryptographicHash>
+
+FileManager::FileManager(QObject *parent)
+ : QThread(parent)
+{
+ quit = false;
+ totalLength = 0;
+ readId = 0;
+ startVerification = false;
+ wokeUp = false;
+ newFile = false;
+ numPieces = 0;
+ verifiedPieces.fill(false);
+}
+
+FileManager::~FileManager()
+{
+ quit = true;
+ cond.wakeOne();
+ wait();
+
+ foreach (QFile *file, files) {
+ file->close();
+ delete file;
+ }
+}
+
+int FileManager::read(int pieceIndex, int offset, int length)
+{
+ ReadRequest request;
+ request.pieceIndex = pieceIndex;
+ request.offset = offset;
+ request.length = length;
+
+ QMutexLocker locker(&mutex);
+ request.id = readId++;
+ readRequests << request;
+
+ if (!wokeUp) {
+ wokeUp = true;
+ QMetaObject::invokeMethod(this, "wakeUp", Qt::QueuedConnection);
+ }
+
+ return request.id;
+}
+
+void FileManager::write(int pieceIndex, int offset, const QByteArray &data)
+{
+ WriteRequest request;
+ request.pieceIndex = pieceIndex;
+ request.offset = offset;
+ request.data = data;
+
+ QMutexLocker locker(&mutex);
+ writeRequests << request;
+
+ if (!wokeUp) {
+ wokeUp = true;
+ QMetaObject::invokeMethod(this, "wakeUp", Qt::QueuedConnection);
+ }
+}
+
+void FileManager::verifyPiece(int pieceIndex)
+{
+ QMutexLocker locker(&mutex);
+ pendingVerificationRequests << pieceIndex;
+ startVerification = true;
+
+ if (!wokeUp) {
+ wokeUp = true;
+ QMetaObject::invokeMethod(this, "wakeUp", Qt::QueuedConnection);
+ }
+}
+
+int FileManager::pieceLengthAt(int pieceIndex) const
+{
+ QMutexLocker locker(&mutex);
+ return (sha1s.size() == pieceIndex + 1)
+ ? (totalLength % pieceLength) : pieceLength;
+}
+
+QBitArray FileManager::completedPieces() const
+{
+ QMutexLocker locker(&mutex);
+ return verifiedPieces;
+}
+
+void FileManager::setCompletedPieces(const QBitArray &pieces)
+{
+ QMutexLocker locker(&mutex);
+ verifiedPieces = pieces;
+}
+
+QString FileManager::errorString() const
+{
+ return errString;
+}
+
+void FileManager::run()
+{
+ if (!generateFiles())
+ return;
+
+ do {
+ {
+ // Go to sleep if there's nothing to do.
+ QMutexLocker locker(&mutex);
+ if (!quit && readRequests.isEmpty() && writeRequests.isEmpty() && !startVerification)
+ cond.wait(&mutex);
+ }
+
+ // Read pending read requests
+ mutex.lock();
+ QList<ReadRequest> newReadRequests = readRequests;
+ readRequests.clear();
+ mutex.unlock();
+ while (!newReadRequests.isEmpty()) {
+ ReadRequest request = newReadRequests.takeFirst();
+ QByteArray block = readBlock(request.pieceIndex, request.offset, request.length);
+ emit dataRead(request.id, request.pieceIndex, request.offset, block);
+ }
+
+ // Write pending write requests
+ mutex.lock();
+ QList<WriteRequest> newWriteRequests = writeRequests;
+ writeRequests.clear();
+ while (!quit && !newWriteRequests.isEmpty()) {
+ WriteRequest request = newWriteRequests.takeFirst();
+ writeBlock(request.pieceIndex, request.offset, request.data);
+ }
+
+ // Process pending verification requests
+ if (startVerification) {
+ newPendingVerificationRequests = pendingVerificationRequests;
+ pendingVerificationRequests.clear();
+ verifyFileContents();
+ startVerification = false;
+ }
+ mutex.unlock();
+ newPendingVerificationRequests.clear();
+
+ } while (!quit);
+
+ // Write pending write requests
+ mutex.lock();
+ QList<WriteRequest> newWriteRequests = writeRequests;
+ writeRequests.clear();
+ mutex.unlock();
+ while (!newWriteRequests.isEmpty()) {
+ WriteRequest request = newWriteRequests.takeFirst();
+ writeBlock(request.pieceIndex, request.offset, request.data);
+ }
+}
+
+void FileManager::startDataVerification()
+{
+ QMutexLocker locker(&mutex);
+ startVerification = true;
+ cond.wakeOne();
+}
+
+bool FileManager::generateFiles()
+{
+ numPieces = -1;
+
+ // Set up the thread local data
+ if (metaInfo.fileForm() == MetaInfo::SingleFileForm) {
+ QMutexLocker locker(&mutex);
+ MetaInfoSingleFile singleFile = metaInfo.singleFile();
+
+ QString prefix;
+ if (!destinationPath.isEmpty()) {
+ prefix = destinationPath;
+ if (!prefix.endsWith("/"))
+ prefix += "/";
+ QDir dir;
+ if (!dir.mkpath(prefix)) {
+ errString = tr("Failed to create directory %1").arg(prefix);
+ emit error();
+ return false;
+ }
+ }
+ QFile *file = new QFile(prefix + singleFile.name);
+ if (!file->open(QFile::ReadWrite)) {
+ errString = tr("Failed to open/create file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ return false;
+ }
+
+ if (file->size() != singleFile.length) {
+ newFile = true;
+ if (!file->resize(singleFile.length)) {
+ errString = tr("Failed to resize file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ return false;
+ }
+ }
+ fileSizes << file->size();
+ files << file;
+ file->close();
+
+ pieceLength = singleFile.pieceLength;
+ totalLength = singleFile.length;
+ sha1s = singleFile.sha1Sums;
+ } else {
+ QMutexLocker locker(&mutex);
+ QDir dir;
+ QString prefix;
+
+ if (!destinationPath.isEmpty()) {
+ prefix = destinationPath;
+ if (!prefix.endsWith("/"))
+ prefix += "/";
+ }
+ if (!metaInfo.name().isEmpty()) {
+ prefix += metaInfo.name();
+ if (!prefix.endsWith("/"))
+ prefix += "/";
+ }
+ if (!dir.mkpath(prefix)) {
+ errString = tr("Failed to create directory %1").arg(prefix);
+ emit error();
+ return false;
+ }
+
+ foreach (const MetaInfoMultiFile &entry, metaInfo.multiFiles()) {
+ QString filePath = QFileInfo(prefix + entry.path).path();
+ if (!QFile::exists(filePath)) {
+ if (!dir.mkpath(filePath)) {
+ errString = tr("Failed to create directory %1").arg(filePath);
+ emit error();
+ return false;
+ }
+ }
+
+ QFile *file = new QFile(prefix + entry.path);
+ if (!file->open(QFile::ReadWrite)) {
+ errString = tr("Failed to open/create file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ return false;
+ }
+
+ if (file->size() != entry.length) {
+ newFile = true;
+ if (!file->resize(entry.length)) {
+ errString = tr("Failed to resize file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ return false;
+ }
+ }
+ fileSizes << file->size();
+ files << file;
+ file->close();
+
+ totalLength += entry.length;
+ }
+
+ sha1s = metaInfo.sha1Sums();
+ pieceLength = metaInfo.pieceLength();
+ }
+ numPieces = sha1s.size();
+ return true;
+}
+
+QByteArray FileManager::readBlock(int pieceIndex, int offset, int length)
+{
+ QByteArray block;
+ qint64 startReadIndex = (quint64(pieceIndex) * pieceLength) + offset;
+ qint64 currentIndex = 0;
+
+ for (int i = 0; !quit && i < files.size() && length > 0; ++i) {
+ QFile *file = files[i];
+ qint64 currentFileSize = fileSizes.at(i);
+ if ((currentIndex + currentFileSize) > startReadIndex) {
+ if (!file->isOpen()) {
+ if (!file->open(QFile::ReadWrite)) {
+ errString = tr("Failed to read from file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ break;
+ }
+ }
+
+ file->seek(startReadIndex - currentIndex);
+ QByteArray chunk = file->read(qMin<qint64>(length, currentFileSize - file->pos()));
+ file->close();
+
+ block += chunk;
+ length -= chunk.size();
+ startReadIndex += chunk.size();
+ if (length < 0) {
+ errString = tr("Failed to read from file %1 (read %3 bytes): %2")
+ .arg(file->fileName()).arg(file->errorString()).arg(length);
+ emit error();
+ break;
+ }
+ }
+ currentIndex += currentFileSize;
+ }
+ return block;
+}
+
+bool FileManager::writeBlock(int pieceIndex, int offset, const QByteArray &data)
+{
+ qint64 startWriteIndex = (qint64(pieceIndex) * pieceLength) + offset;
+ qint64 currentIndex = 0;
+ int bytesToWrite = data.size();
+ int written = 0;
+
+ for (int i = 0; !quit && i < files.size(); ++i) {
+ QFile *file = files[i];
+ qint64 currentFileSize = fileSizes.at(i);
+
+ if ((currentIndex + currentFileSize) > startWriteIndex) {
+ if (!file->isOpen()) {
+ if (!file->open(QFile::ReadWrite)) {
+ errString = tr("Failed to write to file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ break;
+ }
+ }
+
+ file->seek(startWriteIndex - currentIndex);
+ qint64 bytesWritten = file->write(data.constData() + written,
+ qMin<qint64>(bytesToWrite, currentFileSize - file->pos()));
+ file->close();
+
+ if (bytesWritten <= 0) {
+ errString = tr("Failed to write to file %1: %2")
+ .arg(file->fileName()).arg(file->errorString());
+ emit error();
+ return false;
+ }
+
+ written += bytesWritten;
+ startWriteIndex += bytesWritten;
+ bytesToWrite -= bytesWritten;
+ if (bytesToWrite == 0)
+ break;
+ }
+ currentIndex += currentFileSize;
+ }
+ return true;
+}
+
+void FileManager::verifyFileContents()
+{
+ // Verify all pieces the first time
+ if (newPendingVerificationRequests.isEmpty()) {
+ if (verifiedPieces.count(true) == 0) {
+ verifiedPieces.resize(sha1s.size());
+
+ int oldPercent = 0;
+ if (!newFile) {
+ int numPieces = sha1s.size();
+
+ for (int index = 0; index < numPieces; ++index) {
+ verifySinglePiece(index);
+
+ int percent = ((index + 1) * 100) / numPieces;
+ if (oldPercent != percent) {
+ emit verificationProgress(percent);
+ oldPercent = percent;
+ }
+ }
+ }
+ }
+ emit verificationDone();
+ return;
+ }
+
+ // Verify all pending pieces
+ foreach (int index, newPendingVerificationRequests)
+ emit pieceVerified(index, verifySinglePiece(index));
+}
+
+bool FileManager::verifySinglePiece(int pieceIndex)
+{
+ QByteArray block = readBlock(pieceIndex, 0, pieceLength);
+ QByteArray sha1Sum = QCryptographicHash::hash(block, QCryptographicHash::Sha1);
+
+ if (sha1Sum != sha1s.at(pieceIndex))
+ return false;
+ verifiedPieces.setBit(pieceIndex);
+ return true;
+}
+
+void FileManager::wakeUp()
+{
+ QMutexLocker locker(&mutex);
+ wokeUp = false;
+ cond.wakeOne();
+}
diff --git a/examples/network/torrent/filemanager.h b/examples/network/torrent/filemanager.h
new file mode 100644
index 0000000000..cf1a0f706b
--- /dev/null
+++ b/examples/network/torrent/filemanager.h
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FILEMANAGER_H
+#define FILEMANAGER_H
+
+#include <QBitArray>
+#include <QList>
+#include <QMutex>
+#include <QThread>
+#include <QWaitCondition>
+
+#include "metainfo.h"
+
+QT_BEGIN_NAMESPACE
+class QByteArray;
+class QFile;
+class QTimerEvent;
+QT_END_NAMESPACE
+
+class FileManager : public QThread
+{
+ Q_OBJECT
+
+public:
+ FileManager(QObject *parent = 0);
+ virtual ~FileManager();
+
+ inline void setMetaInfo(const MetaInfo &info) { metaInfo = info; }
+ inline void setDestinationFolder(const QString &directory) { destinationPath = directory; }
+
+ int read(int pieceIndex, int offset, int length);
+ void write(int pieceIndex, int offset, const QByteArray &data);
+ void verifyPiece(int pieceIndex);
+ inline qint64 totalSize() const { return totalLength; }
+
+ inline int pieceCount() const { return numPieces; }
+ int pieceLengthAt(int pieceIndex) const;
+
+ QBitArray completedPieces() const;
+ void setCompletedPieces(const QBitArray &pieces);
+
+ QString errorString() const;
+
+public slots:
+ void startDataVerification();
+
+signals:
+ void dataRead(int id, int pieceIndex, int offset, const QByteArray &data);
+ void error();
+ void verificationProgress(int percent);
+ void verificationDone();
+ void pieceVerified(int pieceIndex, bool verified);
+
+protected:
+ void run();
+
+private slots:
+ bool verifySinglePiece(int pieceIndex);
+ void wakeUp();
+
+private:
+ bool generateFiles();
+ QByteArray readBlock(int pieceIndex, int offset, int length);
+ bool writeBlock(int pieceIndex, int offset, const QByteArray &data);
+ void verifyFileContents();
+
+ struct WriteRequest {
+ int pieceIndex;
+ int offset;
+ QByteArray data;
+ };
+ struct ReadRequest {
+ int pieceIndex;
+ int offset;
+ int length;
+ int id;
+ };
+
+ QString errString;
+ QString destinationPath;
+ MetaInfo metaInfo;
+ QList<QFile *> files;
+ QList<QByteArray> sha1s;
+ QBitArray verifiedPieces;
+
+ bool newFile;
+ int pieceLength;
+ qint64 totalLength;
+ int numPieces;
+ int readId;
+ bool startVerification;
+ bool quit;
+ bool wokeUp;
+
+ QList<WriteRequest> writeRequests;
+ QList<ReadRequest> readRequests;
+ QList<int> pendingVerificationRequests;
+ QList<int> newPendingVerificationRequests;
+ QList<qint64> fileSizes;
+
+ mutable QMutex mutex;
+ mutable QWaitCondition cond;
+};
+
+#endif
diff --git a/examples/network/torrent/forms/addtorrentform.ui b/examples/network/torrent/forms/addtorrentform.ui
new file mode 100644
index 0000000000..950bb67119
--- /dev/null
+++ b/examples/network/torrent/forms/addtorrentform.ui
@@ -0,0 +1,266 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>AddTorrentFile</class>
+ <widget class="QDialog" name="AddTorrentFile" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>464</width>
+ <height>385</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Add a torrent</string>
+ </property>
+ <property name="sizeGripEnabled" >
+ <bool>false</bool>
+ </property>
+ <property name="modal" >
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>8</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>Select a torrent source</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>8</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="6" column="0" >
+ <widget class="QLabel" name="label_4" >
+ <property name="text" >
+ <string>Destination:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2" >
+ <widget class="QLineEdit" name="torrentFile" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Tracker URL:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <widget class="QPushButton" name="browseTorrents" >
+ <property name="text" >
+ <string>Browse</string>
+ </property>
+ <property name="default" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="label_5" >
+ <property name="text" >
+ <string>File(s):</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Size:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_6" >
+ <property name="text" >
+ <string>Creator:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" colspan="3" >
+ <widget class="QTextEdit" name="torrentContents" >
+ <property name="focusPolicy" >
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="tabChangesFocus" >
+ <bool>true</bool>
+ </property>
+ <property name="lineWrapMode" >
+ <enum>QTextEdit::NoWrap</enum>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1" colspan="2" >
+ <widget class="QLineEdit" name="destinationFolder" >
+ <property name="focusPolicy" >
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="3" >
+ <widget class="QLabel" name="announceUrl" >
+ <property name="text" >
+ <string>&lt;none></string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Torrent file:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="3" >
+ <widget class="QPushButton" name="browseDestination" >
+ <property name="text" >
+ <string>Browse</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="label_7" >
+ <property name="text" >
+ <string>Comment:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="3" >
+ <widget class="QLabel" name="commentLabel" >
+ <property name="text" >
+ <string>&lt;none></string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="3" >
+ <widget class="QLabel" name="creatorLabel" >
+ <property name="text" >
+ <string>&lt;none></string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="3" >
+ <widget class="QLabel" name="sizeLabel" >
+ <property name="text" >
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ <widget class="QWidget" name="widget" >
+ <property name="geometry" >
+ <rect>
+ <x>10</x>
+ <y>40</y>
+ <width>364</width>
+ <height>33</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>131</width>
+ <height>31</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="okButton" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>&amp;OK</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="cancelButton" >
+ <property name="text" >
+ <string>&amp;Cancel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <tabstops>
+ <tabstop>torrentFile</tabstop>
+ <tabstop>browseTorrents</tabstop>
+ <tabstop>torrentContents</tabstop>
+ <tabstop>destinationFolder</tabstop>
+ <tabstop>browseDestination</tabstop>
+ <tabstop>okButton</tabstop>
+ <tabstop>cancelButton</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>okButton</sender>
+ <signal>clicked()</signal>
+ <receiver>AddTorrentFile</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>278</x>
+ <y>253</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>96</x>
+ <y>254</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>cancelButton</sender>
+ <signal>clicked()</signal>
+ <receiver>AddTorrentFile</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>369</x>
+ <y>253</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>179</x>
+ <y>282</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/network/torrent/icons.qrc b/examples/network/torrent/icons.qrc
new file mode 100644
index 0000000000..9541ef7600
--- /dev/null
+++ b/examples/network/torrent/icons.qrc
@@ -0,0 +1,12 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>icons/peertopeer.png</file>
+ <file>icons/1uparrow.png</file>
+ <file>icons/1downarrow.png</file>
+ <file>icons/bottom.png</file>
+ <file>icons/player_pause.png</file>
+ <file>icons/player_play.png</file>
+ <file>icons/player_stop.png</file>
+ <file>icons/exit.png</file>
+</qresource>
+</RCC>
diff --git a/examples/network/torrent/icons/1downarrow.png b/examples/network/torrent/icons/1downarrow.png
new file mode 100644
index 0000000000..08403b82ba
--- /dev/null
+++ b/examples/network/torrent/icons/1downarrow.png
Binary files differ
diff --git a/examples/network/torrent/icons/1uparrow.png b/examples/network/torrent/icons/1uparrow.png
new file mode 100644
index 0000000000..f044811787
--- /dev/null
+++ b/examples/network/torrent/icons/1uparrow.png
Binary files differ
diff --git a/examples/network/torrent/icons/bottom.png b/examples/network/torrent/icons/bottom.png
new file mode 100644
index 0000000000..fe66b5d028
--- /dev/null
+++ b/examples/network/torrent/icons/bottom.png
Binary files differ
diff --git a/examples/network/torrent/icons/edit_add.png b/examples/network/torrent/icons/edit_add.png
new file mode 100644
index 0000000000..85b022e7a4
--- /dev/null
+++ b/examples/network/torrent/icons/edit_add.png
Binary files differ
diff --git a/examples/network/torrent/icons/edit_remove.png b/examples/network/torrent/icons/edit_remove.png
new file mode 100644
index 0000000000..93361f5225
--- /dev/null
+++ b/examples/network/torrent/icons/edit_remove.png
Binary files differ
diff --git a/examples/network/torrent/icons/exit.png b/examples/network/torrent/icons/exit.png
new file mode 100644
index 0000000000..2f7ff43a71
--- /dev/null
+++ b/examples/network/torrent/icons/exit.png
Binary files differ
diff --git a/examples/network/torrent/icons/peertopeer.png b/examples/network/torrent/icons/peertopeer.png
new file mode 100644
index 0000000000..f4856dcec5
--- /dev/null
+++ b/examples/network/torrent/icons/peertopeer.png
Binary files differ
diff --git a/examples/network/torrent/icons/player_pause.png b/examples/network/torrent/icons/player_pause.png
new file mode 100644
index 0000000000..8c9bcc4556
--- /dev/null
+++ b/examples/network/torrent/icons/player_pause.png
Binary files differ
diff --git a/examples/network/torrent/icons/player_play.png b/examples/network/torrent/icons/player_play.png
new file mode 100644
index 0000000000..70daa339be
--- /dev/null
+++ b/examples/network/torrent/icons/player_play.png
Binary files differ
diff --git a/examples/network/torrent/icons/player_stop.png b/examples/network/torrent/icons/player_stop.png
new file mode 100644
index 0000000000..ce6585ae84
--- /dev/null
+++ b/examples/network/torrent/icons/player_stop.png
Binary files differ
diff --git a/examples/network/torrent/icons/stop.png b/examples/network/torrent/icons/stop.png
new file mode 100644
index 0000000000..52e593ab21
--- /dev/null
+++ b/examples/network/torrent/icons/stop.png
Binary files differ
diff --git a/examples/network/torrent/main.cpp b/examples/network/torrent/main.cpp
new file mode 100644
index 0000000000..1023ae85a7
--- /dev/null
+++ b/examples/network/torrent/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QApplication>
+#include <QtCore>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.");
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ Q_INIT_RESOURCE(icons);
+
+ MainWindow window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp
new file mode 100644
index 0000000000..06dfca1ba2
--- /dev/null
+++ b/examples/network/torrent/mainwindow.cpp
@@ -0,0 +1,712 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "addtorrentdialog.h"
+#include "mainwindow.h"
+#include "ratecontroller.h"
+#include "torrentclient.h"
+
+// TorrentView extends QTreeWidget to allow drag and drop.
+class TorrentView : public QTreeWidget
+{
+ Q_OBJECT
+public:
+ TorrentView(QWidget *parent = 0);
+
+signals:
+ void fileDropped(const QString &fileName);
+
+protected:
+ void dragMoveEvent(QDragMoveEvent *event);
+ void dropEvent(QDropEvent *event);
+};
+
+// TorrentViewDelegate is used to draw the progress bars.
+class TorrentViewDelegate : public QItemDelegate
+{
+ Q_OBJECT
+public:
+ inline TorrentViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow) {}
+
+ inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index ) const
+ {
+ if (index.column() != 2) {
+ QItemDelegate::paint(painter, option, index);
+ return;
+ }
+
+ // Set up a QStyleOptionProgressBar to precisely mimic the
+ // environment of a progress bar.
+ QStyleOptionProgressBar progressBarOption;
+ progressBarOption.state = QStyle::State_Enabled;
+ progressBarOption.direction = QApplication::layoutDirection();
+ progressBarOption.rect = option.rect;
+ progressBarOption.fontMetrics = QApplication::fontMetrics();
+ progressBarOption.minimum = 0;
+ progressBarOption.maximum = 100;
+ progressBarOption.textAlignment = Qt::AlignCenter;
+ progressBarOption.textVisible = true;
+
+ // Set the progress and text values of the style option.
+ int progress = qobject_cast<MainWindow *>(parent())->clientForRow(index.row())->progress();
+ progressBarOption.progress = progress < 0 ? 0 : progress;
+ progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
+
+ // Draw the progress bar onto the view.
+ QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
+ }
+};
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), quitDialog(0), saveChanges(false)
+{
+ // Initialize some static strings
+ QStringList headers;
+ headers << tr("Torrent") << tr("Peers/Seeds") << tr("Progress")
+ << tr("Down rate") << tr("Up rate") << tr("Status");
+
+ // Main torrent list
+ torrentView = new TorrentView(this);
+ torrentView->setItemDelegate(new TorrentViewDelegate(this));
+ torrentView->setHeaderLabels(headers);
+ torrentView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ torrentView->setAlternatingRowColors(true);
+ torrentView->setRootIsDecorated(false);
+ setCentralWidget(torrentView);
+
+ // Set header resize modes and initial section sizes
+ QFontMetrics fm = fontMetrics();
+ QHeaderView *header = torrentView->header();
+ header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
+ header->resizeSection(1, fm.width(headers.at(1) + " "));
+ header->resizeSection(2, fm.width(headers.at(2) + " "));
+ header->resizeSection(3, qMax(fm.width(headers.at(3) + " "), fm.width(" 1234.0 KB/s ")));
+ header->resizeSection(4, qMax(fm.width(headers.at(4) + " "), fm.width(" 1234.0 KB/s ")));
+ header->resizeSection(5, qMax(fm.width(headers.at(5) + " "), fm.width(tr("Downloading") + " ")));
+
+ // Create common actions
+ QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.png"), tr("Add &new torrent"), this);
+ pauseTorrentAction = new QAction(QIcon(":/icons/player_pause.png"), tr("&Pause torrent"), this);
+ removeTorrentAction = new QAction(QIcon(":/icons/player_stop.png"), tr("&Remove torrent"), this);
+
+ // File menu
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(newTorrentAction);
+ fileMenu->addAction(pauseTorrentAction);
+ fileMenu->addAction(removeTorrentAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(QIcon(":/icons/exit.png"), tr("E&xit"), this, SLOT(close()));
+
+ // Help menu
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(tr("&About"), this, SLOT(about()));
+ helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+
+ // Top toolbar
+ QToolBar *topBar = new QToolBar(tr("Tools"));
+ addToolBar(Qt::TopToolBarArea, topBar);
+ topBar->setMovable(false);
+ topBar->addAction(newTorrentAction);
+ topBar->addAction(removeTorrentAction);
+ topBar->addAction(pauseTorrentAction);
+ topBar->addSeparator();
+ downActionTool = topBar->addAction(QIcon(tr(":/icons/1downarrow.png")), tr("Move down"));
+ upActionTool = topBar->addAction(QIcon(tr(":/icons/1uparrow.png")), tr("Move up"));
+
+ // Bottom toolbar
+ QToolBar *bottomBar = new QToolBar(tr("Rate control"));
+ addToolBar(Qt::BottomToolBarArea, bottomBar);
+ bottomBar->setMovable(false);
+ downloadLimitSlider = new QSlider(Qt::Horizontal);
+ downloadLimitSlider->setRange(0, 1000);
+ bottomBar->addWidget(new QLabel(tr("Max download:")));
+ bottomBar->addWidget(downloadLimitSlider);
+ bottomBar->addWidget((downloadLimitLabel = new QLabel(tr("0 KB/s"))));
+ downloadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
+ bottomBar->addSeparator();
+ uploadLimitSlider = new QSlider(Qt::Horizontal);
+ uploadLimitSlider->setRange(0, 1000);
+ bottomBar->addWidget(new QLabel(tr("Max upload:")));
+ bottomBar->addWidget(uploadLimitSlider);
+ bottomBar->addWidget((uploadLimitLabel = new QLabel(tr("0 KB/s"))));
+ uploadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing()));
+
+ // Set up connections
+ connect(torrentView, SIGNAL(itemSelectionChanged()),
+ this, SLOT(setActionsEnabled()));
+ connect(torrentView, SIGNAL(fileDropped(QString)),
+ this, SLOT(acceptFileDrop(QString)));
+ connect(uploadLimitSlider, SIGNAL(valueChanged(int)),
+ this, SLOT(setUploadLimit(int)));
+ connect(downloadLimitSlider, SIGNAL(valueChanged(int)),
+ this, SLOT(setDownloadLimit(int)));
+ connect(newTorrentAction, SIGNAL(triggered()),
+ this, SLOT(addTorrent()));
+ connect(pauseTorrentAction, SIGNAL(triggered()),
+ this, SLOT(pauseTorrent()));
+ connect(removeTorrentAction, SIGNAL(triggered()),
+ this, SLOT(removeTorrent()));
+ connect(upActionTool, SIGNAL(triggered(bool)),
+ this, SLOT(moveTorrentUp()));
+ connect(downActionTool, SIGNAL(triggered(bool)),
+ this, SLOT(moveTorrentDown()));
+
+ // Load settings and start
+ setWindowTitle(tr("Torrent Client"));
+ setActionsEnabled();
+ QMetaObject::invokeMethod(this, "loadSettings", Qt::QueuedConnection);
+}
+
+QSize MainWindow::sizeHint() const
+{
+ const QHeaderView *header = torrentView->header();
+
+ // Add up the sizes of all header sections. The last section is
+ // stretched, so its size is relative to the size of the width;
+ // instead of counting it, we count the size of its largest value.
+ int width = fontMetrics().width(tr("Downloading") + " ");
+ for (int i = 0; i < header->count() - 1; ++i)
+ width += header->sectionSize(i);
+
+ return QSize(width, QMainWindow::sizeHint().height())
+ .expandedTo(QApplication::globalStrut());
+}
+
+const TorrentClient *MainWindow::clientForRow(int row) const
+{
+ // Return the client at the given row.
+ return jobs.at(row).client;
+}
+
+int MainWindow::rowOfClient(TorrentClient *client) const
+{
+ // Return the row that displays this client's status, or -1 if the
+ // client is not known.
+ int row = 0;
+ foreach (Job job, jobs) {
+ if (job.client == client)
+ return row;
+ ++row;
+ }
+ return -1;
+}
+
+void MainWindow::loadSettings()
+{
+ // Load base settings (last working directory, upload/download limits).
+ QSettings settings("Trolltech", "Torrent");
+ lastDirectory = settings.value("LastDirectory").toString();
+ if (lastDirectory.isEmpty())
+ lastDirectory = QDir::currentPath();
+ int up = settings.value("UploadLimit").toInt();
+ int down = settings.value("DownloadLimit").toInt();
+ uploadLimitSlider->setValue(up ? up : 170);
+ downloadLimitSlider->setValue(down ? down : 550);
+
+ // Resume all previous downloads.
+ int size = settings.beginReadArray("Torrents");
+ for (int i = 0; i < size; ++i) {
+ settings.setArrayIndex(i);
+ QByteArray resumeState = settings.value("resumeState").toByteArray();
+ QString fileName = settings.value("sourceFileName").toString();
+ QString dest = settings.value("destinationFolder").toString();
+
+ if (addTorrent(fileName, dest, resumeState)) {
+ TorrentClient *client = jobs.last().client;
+ client->setDownloadedBytes(settings.value("downloadedBytes").toLongLong());
+ client->setUploadedBytes(settings.value("uploadedBytes").toLongLong());
+ }
+ }
+}
+
+bool MainWindow::addTorrent()
+{
+ // Show the file dialog, let the user select what torrent to start downloading.
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Choose a torrent file"),
+ lastDirectory,
+ tr("Torrents (*.torrent);;"
+ " All files (*.*)"));
+ if (fileName.isEmpty())
+ return false;
+ lastDirectory = QFileInfo(fileName).absolutePath();
+
+ // Show the "Add Torrent" dialog.
+ AddTorrentDialog *addTorrentDialog = new AddTorrentDialog(this);
+ addTorrentDialog->setTorrent(fileName);
+ addTorrentDialog->deleteLater();
+ if (!addTorrentDialog->exec())
+ return false;
+
+ // Add the torrent to our list of downloads
+ addTorrent(fileName, addTorrentDialog->destinationFolder());
+ if (!saveChanges) {
+ saveChanges = true;
+ QTimer::singleShot(1000, this, SLOT(saveSettings()));
+ }
+ return true;
+}
+
+void MainWindow::removeTorrent()
+{
+ // Find the row of the current item, and find the torrent client
+ // for that row.
+ int row = torrentView->indexOfTopLevelItem(torrentView->currentItem());
+ TorrentClient *client = jobs.at(row).client;
+
+ // Stop the client.
+ client->disconnect();
+ connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
+ client->stop();
+
+ // Remove the row from the view.
+ delete torrentView->takeTopLevelItem(row);
+ jobs.removeAt(row);
+ setActionsEnabled();
+
+ saveChanges = true;
+ saveSettings();
+}
+
+void MainWindow::torrentStopped()
+{
+ // Schedule the client for deletion.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ client->deleteLater();
+
+ // If the quit dialog is shown, update its progress.
+ if (quitDialog) {
+ if (++jobsStopped == jobsToStop)
+ quitDialog->close();
+ }
+}
+
+void MainWindow::torrentError(TorrentClient::Error)
+{
+ // Delete the client.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+ QString fileName = jobs.at(row).torrentFileName;
+ jobs.removeAt(row);
+
+ // Display the warning.
+ QMessageBox::warning(this, tr("Error"),
+ tr("An error occurred while downloading %0: %1")
+ .arg(fileName)
+ .arg(client->errorString()));
+
+ delete torrentView->takeTopLevelItem(row);
+ client->deleteLater();
+}
+
+bool MainWindow::addTorrent(const QString &fileName, const QString &destinationFolder,
+ const QByteArray &resumeState)
+{
+ // Check if the torrent is already being downloaded.
+ foreach (Job job, jobs) {
+ if (job.torrentFileName == fileName && job.destinationDirectory == destinationFolder) {
+ QMessageBox::warning(this, tr("Already downloading"),
+ tr("The torrent file %1 is "
+ "already being downloaded.").arg(fileName));
+ return false;
+ }
+ }
+
+ // Create a new torrent client and attempt to parse the torrent data.
+ TorrentClient *client = new TorrentClient(this);
+ if (!client->setTorrent(fileName)) {
+ QMessageBox::warning(this, tr("Error"),
+ tr("The torrent file %1 cannot not be opened/resumed.").arg(fileName));
+ delete client;
+ return false;
+ }
+ client->setDestinationFolder(destinationFolder);
+ client->setDumpedState(resumeState);
+
+ // Setup the client connections.
+ connect(client, SIGNAL(stateChanged(TorrentClient::State)), this, SLOT(updateState(TorrentClient::State)));
+ connect(client, SIGNAL(peerInfoUpdated()), this, SLOT(updatePeerInfo()));
+ connect(client, SIGNAL(progressUpdated(int)), this, SLOT(updateProgress(int)));
+ connect(client, SIGNAL(downloadRateUpdated(int)), this, SLOT(updateDownloadRate(int)));
+ connect(client, SIGNAL(uploadRateUpdated(int)), this, SLOT(updateUploadRate(int)));
+ connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
+ connect(client, SIGNAL(error(TorrentClient::Error)), this, SLOT(torrentError(TorrentClient::Error)));
+
+ // Add the client to the list of downloading jobs.
+ Job job;
+ job.client = client;
+ job.torrentFileName = fileName;
+ job.destinationDirectory = destinationFolder;
+ jobs << job;
+
+ // Create and add a row in the torrent view for this download.
+ QTreeWidgetItem *item = new QTreeWidgetItem(torrentView);
+
+ QString baseFileName = QFileInfo(fileName).fileName();
+ if (baseFileName.toLower().endsWith(".torrent"))
+ baseFileName.remove(baseFileName.size() - 8);
+
+ item->setText(0, baseFileName);
+ item->setToolTip(0, tr("Torrent: %1<br>Destination: %2")
+ .arg(baseFileName).arg(destinationFolder));
+ item->setText(1, tr("0/0"));
+ item->setText(2, "0");
+ item->setText(3, "0.0 KB/s");
+ item->setText(4, "0.0 KB/s");
+ item->setText(5, tr("Idle"));
+ item->setFlags(item->flags() & ~Qt::ItemIsEditable);
+ item->setTextAlignment(1, Qt::AlignHCenter);
+
+ if (!saveChanges) {
+ saveChanges = true;
+ QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ }
+ client->start();
+ return true;
+}
+
+void MainWindow::saveSettings()
+{
+ if (!saveChanges)
+ return;
+ saveChanges = false;
+
+ // Prepare and reset the settings
+ QSettings settings("Trolltech", "Torrent");
+ settings.clear();
+
+ settings.setValue("LastDirectory", lastDirectory);
+ settings.setValue("UploadLimit", uploadLimitSlider->value());
+ settings.setValue("DownloadLimit", downloadLimitSlider->value());
+
+ // Store data on all known torrents
+ settings.beginWriteArray("Torrents");
+ for (int i = 0; i < jobs.size(); ++i) {
+ settings.setArrayIndex(i);
+ settings.setValue("sourceFileName", jobs.at(i).torrentFileName);
+ settings.setValue("destinationFolder", jobs.at(i).destinationDirectory);
+ settings.setValue("uploadedBytes", jobs.at(i).client->uploadedBytes());
+ settings.setValue("downloadedBytes", jobs.at(i).client->downloadedBytes());
+ settings.setValue("resumeState", jobs.at(i).client->dumpedState());
+ }
+ settings.endArray();
+ settings.sync();
+}
+
+void MainWindow::updateState(TorrentClient::State)
+{
+ // Update the state string whenever the client's state changes.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+ QTreeWidgetItem *item = torrentView->topLevelItem(row);
+ if (item) {
+ item->setToolTip(0, tr("Torrent: %1<br>Destination: %2<br>State: %3")
+ .arg(jobs.at(row).torrentFileName)
+ .arg(jobs.at(row).destinationDirectory)
+ .arg(client->stateString()));
+
+ item->setText(5, client->stateString());
+ }
+ setActionsEnabled();
+}
+
+void MainWindow::updatePeerInfo()
+{
+ // Update the number of connected, visited, seed and leecher peers.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+
+ QTreeWidgetItem *item = torrentView->topLevelItem(row);
+ item->setText(1, tr("%1/%2").arg(client->connectedPeerCount())
+ .arg(client->seedCount()));
+}
+
+void MainWindow::updateProgress(int percent)
+{
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+
+ // Update the progressbar.
+ QTreeWidgetItem *item = torrentView->topLevelItem(row);
+ if (item)
+ item->setText(2, QString::number(percent));
+}
+
+void MainWindow::setActionsEnabled()
+{
+ // Find the view item and client for the current row, and update
+ // the states of the actions.
+ QTreeWidgetItem *item = 0;
+ if (!torrentView->selectedItems().isEmpty())
+ item = torrentView->selectedItems().first();
+ TorrentClient *client = item ? jobs.at(torrentView->indexOfTopLevelItem(item)).client : 0;
+ bool pauseEnabled = client && ((client->state() == TorrentClient::Paused)
+ || (client->state() > TorrentClient::Preparing));
+
+ removeTorrentAction->setEnabled(item != 0);
+ pauseTorrentAction->setEnabled(item != 0 && pauseEnabled);
+
+ if (client && client->state() == TorrentClient::Paused) {
+ pauseTorrentAction->setIcon(QIcon(":/icons/player_play.png"));
+ pauseTorrentAction->setText(tr("Resume torrent"));
+ } else {
+ pauseTorrentAction->setIcon(QIcon(":/icons/player_pause.png"));
+ pauseTorrentAction->setText(tr("Pause torrent"));
+ }
+
+ int row = torrentView->indexOfTopLevelItem(item);
+ upActionTool->setEnabled(item && row != 0);
+ downActionTool->setEnabled(item && row != jobs.size() - 1);
+}
+
+void MainWindow::updateDownloadRate(int bytesPerSecond)
+{
+ // Update the download rate.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+ QString num;
+ num.sprintf("%.1f KB/s", bytesPerSecond / 1024.0);
+ torrentView->topLevelItem(row)->setText(3, num);
+
+ if (!saveChanges) {
+ saveChanges = true;
+ QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ }
+}
+
+void MainWindow::updateUploadRate(int bytesPerSecond)
+{
+ // Update the upload rate.
+ TorrentClient *client = qobject_cast<TorrentClient *>(sender());
+ int row = rowOfClient(client);
+ QString num;
+ num.sprintf("%.1f KB/s", bytesPerSecond / 1024.0);
+ torrentView->topLevelItem(row)->setText(4, num);
+
+ if (!saveChanges) {
+ saveChanges = true;
+ QTimer::singleShot(5000, this, SLOT(saveSettings()));
+ }
+}
+
+void MainWindow::pauseTorrent()
+{
+ // Pause or unpause the current torrent.
+ int row = torrentView->indexOfTopLevelItem(torrentView->currentItem());
+ TorrentClient *client = jobs.at(row).client;
+ client->setPaused(client->state() != TorrentClient::Paused);
+ setActionsEnabled();
+}
+
+void MainWindow::moveTorrentUp()
+{
+ QTreeWidgetItem *item = torrentView->currentItem();
+ int row = torrentView->indexOfTopLevelItem(item);
+ if (row == 0)
+ return;
+
+ Job tmp = jobs.at(row - 1);
+ jobs[row - 1] = jobs[row];
+ jobs[row] = tmp;
+
+ QTreeWidgetItem *itemAbove = torrentView->takeTopLevelItem(row - 1);
+ torrentView->insertTopLevelItem(row, itemAbove);
+ setActionsEnabled();
+}
+
+void MainWindow::moveTorrentDown()
+{
+ QTreeWidgetItem *item = torrentView->currentItem();
+ int row = torrentView->indexOfTopLevelItem(item);
+ if (row == jobs.size() - 1)
+ return;
+
+ Job tmp = jobs.at(row + 1);
+ jobs[row + 1] = jobs[row];
+ jobs[row] = tmp;
+
+ QTreeWidgetItem *itemAbove = torrentView->takeTopLevelItem(row + 1);
+ torrentView->insertTopLevelItem(row, itemAbove);
+ setActionsEnabled();
+}
+
+static int rateFromValue(int value)
+{
+ int rate = 0;
+ if (value >= 0 && value < 250) {
+ rate = 1 + int(value * 0.124);
+ } else if (value < 500) {
+ rate = 32 + int((value - 250) * 0.384);
+ } else if (value < 750) {
+ rate = 128 + int((value - 500) * 1.536);
+ } else {
+ rate = 512 + int((value - 750) * 6.1445);
+ }
+ return rate;
+}
+
+void MainWindow::setUploadLimit(int value)
+{
+ int rate = rateFromValue(value);
+ uploadLimitLabel->setText(tr("%1 KB/s").arg(QString().sprintf("%4d", rate)));
+ RateController::instance()->setUploadLimit(rate * 1024);
+}
+
+void MainWindow::setDownloadLimit(int value)
+{
+ int rate = rateFromValue(value);
+ downloadLimitLabel->setText(tr("%1 KB/s").arg(QString().sprintf("%4d", rate)));
+ RateController::instance()->setDownloadLimit(rate * 1024);
+}
+
+void MainWindow::about()
+{
+ QLabel *icon = new QLabel;
+ icon->setPixmap(QPixmap(":/icons/peertopeer.png"));
+
+ QLabel *text = new QLabel;
+ text->setWordWrap(true);
+ text->setText("<p>The <b>Torrent Client</b> example demonstrates how to"
+ " write a complete peer-to-peer file sharing"
+ " application using Qt's network and thread classes.</p>"
+ "<p>This feature complete client implementation of"
+ " the BitTorrent protocol can efficiently"
+ " maintain several hundred network connections"
+ " simultaneously.</p>");
+
+ QPushButton *quitButton = new QPushButton("OK");
+
+ QHBoxLayout *topLayout = new QHBoxLayout;
+ topLayout->setMargin(10);
+ topLayout->setSpacing(10);
+ topLayout->addWidget(icon);
+ topLayout->addWidget(text);
+
+ QHBoxLayout *bottomLayout = new QHBoxLayout;
+ bottomLayout->addStretch();
+ bottomLayout->addWidget(quitButton);
+ bottomLayout->addStretch();
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(topLayout);
+ mainLayout->addLayout(bottomLayout);
+
+ QDialog about(this);
+ about.setModal(true);
+ about.setWindowTitle(tr("About Torrent Client"));
+ about.setLayout(mainLayout);
+
+ connect(quitButton, SIGNAL(clicked()), &about, SLOT(close()));
+
+ about.exec();
+}
+
+void MainWindow::acceptFileDrop(const QString &fileName)
+{
+ // Create and show the "Add Torrent" dialog.
+ AddTorrentDialog *addTorrentDialog = new AddTorrentDialog;
+ lastDirectory = QFileInfo(fileName).absolutePath();
+ addTorrentDialog->setTorrent(fileName);
+ addTorrentDialog->deleteLater();
+ if (!addTorrentDialog->exec())
+ return;
+
+ // Add the torrent to our list of downloads.
+ addTorrent(fileName, addTorrentDialog->destinationFolder());
+ saveSettings();
+}
+
+void MainWindow::closeEvent(QCloseEvent *)
+{
+ if (jobs.isEmpty())
+ return;
+
+ // Save upload / download numbers.
+ saveSettings();
+ saveChanges = false;
+
+ quitDialog = new QProgressDialog(tr("Disconnecting from trackers"), tr("Abort"), 0, jobsToStop, this);
+
+ // Stop all clients, remove the rows from the view and wait for
+ // them to signal that they have stopped.
+ jobsToStop = 0;
+ jobsStopped = 0;
+ foreach (Job job, jobs) {
+ ++jobsToStop;
+ TorrentClient *client = job.client;
+ client->disconnect();
+ connect(client, SIGNAL(stopped()), this, SLOT(torrentStopped()));
+ client->stop();
+ delete torrentView->takeTopLevelItem(0);
+ }
+
+ if (jobsToStop > jobsStopped)
+ quitDialog->exec();
+ quitDialog->deleteLater();
+ quitDialog = 0;
+}
+
+TorrentView::TorrentView(QWidget *parent)
+ : QTreeWidget(parent)
+{
+ setAcceptDrops(true);
+}
+
+void TorrentView::dragMoveEvent(QDragMoveEvent *event)
+{
+ // Accept file actions with a '.torrent' extension.
+ QUrl url(event->mimeData()->text());
+ if (url.isValid() && url.scheme().toLower() == "file"
+ && url.path().toLower().endsWith(".torrent"))
+ event->acceptProposedAction();
+}
+
+void TorrentView::dropEvent(QDropEvent *event)
+{
+ // Accept drops if the file has a '.torrent' extension and it
+ // exists.
+ QString fileName = QUrl(event->mimeData()->text()).path();
+ if (QFile::exists(fileName) && fileName.toLower().endsWith(".torrent"))
+ emit fileDropped(fileName);
+}
+
+#include "mainwindow.moc"
diff --git a/examples/network/torrent/mainwindow.h b/examples/network/torrent/mainwindow.h
new file mode 100644
index 0000000000..0d42c91ce4
--- /dev/null
+++ b/examples/network/torrent/mainwindow.h
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QStringList>
+#include <QMainWindow>
+
+#include "torrentclient.h"
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QCloseEvent;
+class QLabel;
+class QProgressDialog;
+class QSlider;
+QT_END_NAMESPACE
+class TorrentView;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+ QSize sizeHint() const;
+ const TorrentClient *clientForRow(int row) const;
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void loadSettings();
+ void saveSettings();
+
+ bool addTorrent();
+ void removeTorrent();
+ void pauseTorrent();
+ void moveTorrentUp();
+ void moveTorrentDown();
+
+ void torrentStopped();
+ void torrentError(TorrentClient::Error error);
+
+ void updateState(TorrentClient::State state);
+ void updatePeerInfo();
+ void updateProgress(int percent);
+ void updateDownloadRate(int bytesPerSecond);
+ void updateUploadRate(int bytesPerSecond);
+
+ void setUploadLimit(int bytes);
+ void setDownloadLimit(int bytes);
+
+ void about();
+ void setActionsEnabled();
+ void acceptFileDrop(const QString &fileName);
+
+private:
+ int rowOfClient(TorrentClient *client) const;
+ bool addTorrent(const QString &fileName, const QString &destinationFolder,
+ const QByteArray &resumeState = QByteArray());
+
+ TorrentView *torrentView;
+ QAction *pauseTorrentAction;
+ QAction *removeTorrentAction;
+ QAction *upActionTool;
+ QAction *downActionTool;
+ QSlider *uploadLimitSlider;
+ QSlider *downloadLimitSlider;
+ QLabel *uploadLimitLabel;
+ QLabel *downloadLimitLabel;
+
+ int uploadLimit;
+ int downloadLimit;
+
+ struct Job {
+ TorrentClient *client;
+ QString torrentFileName;
+ QString destinationDirectory;
+ };
+ QList<Job> jobs;
+ int jobsStopped;
+ int jobsToStop;
+
+ QString lastDirectory;
+ QProgressDialog *quitDialog;
+
+ bool saveChanges;
+};
+
+#endif
diff --git a/examples/network/torrent/metainfo.cpp b/examples/network/torrent/metainfo.cpp
new file mode 100644
index 0000000000..ba55ebace6
--- /dev/null
+++ b/examples/network/torrent/metainfo.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "bencodeparser.h"
+#include "metainfo.h"
+
+#include <QDateTime>
+#include <QMetaType>
+#include <QString>
+
+MetaInfo::MetaInfo()
+{
+ clear();
+}
+
+void MetaInfo::clear()
+{
+ errString = "Unknown error";
+ content.clear();
+ infoData.clear();
+ metaInfoMultiFiles.clear();
+ metaInfoAnnounce.clear();
+ metaInfoAnnounceList.clear();
+ metaInfoCreationDate = QDateTime();
+ metaInfoComment.clear();
+ metaInfoCreatedBy.clear();
+ metaInfoName.clear();
+ metaInfoPieceLength = 0;
+ metaInfoSha1Sums.clear();
+}
+
+bool MetaInfo::parse(const QByteArray &data)
+{
+ clear();
+ content = data;
+
+ BencodeParser parser;
+ if (!parser.parse(content)) {
+ errString = parser.errorString();
+ return false;
+ }
+
+ infoData = parser.infoSection();
+
+ QMap<QByteArray, QVariant> dict = parser.dictionary();
+ if (!dict.contains("info"))
+ return false;
+
+ QMap<QByteArray, QVariant> info = qvariant_cast<Dictionary>(dict.value("info"));
+
+ if (info.contains("files")) {
+ metaInfoFileForm = MultiFileForm;
+
+ QList<QVariant> files = info.value("files").toList();
+
+ for (int i = 0; i < files.size(); ++i) {
+ QMap<QByteArray, QVariant> file = qvariant_cast<Dictionary>(files.at(i));
+ QList<QVariant> pathElements = file.value("path").toList();
+ QByteArray path;
+ foreach (QVariant p, pathElements) {
+ if (!path.isEmpty())
+ path += "/";
+ path += p.toByteArray();
+ }
+
+ MetaInfoMultiFile multiFile;
+ multiFile.length = file.value("length").toLongLong();
+ multiFile.path = QString::fromUtf8(path);
+ multiFile.md5sum = file.value("md5sum").toByteArray();
+ metaInfoMultiFiles << multiFile;
+ }
+
+ metaInfoName = QString::fromUtf8(info.value("name").toByteArray());
+ metaInfoPieceLength = info.value("piece length").toInt();
+ QByteArray pieces = info.value("pieces").toByteArray();
+ for (int i = 0; i < pieces.size(); i += 20)
+ metaInfoSha1Sums << pieces.mid(i, 20);
+ } else if (info.contains("length")) {
+ metaInfoFileForm = SingleFileForm;
+ metaInfoSingleFile.length = info.value("length").toLongLong();
+ metaInfoSingleFile.md5sum = info.value("md5sum").toByteArray();
+ metaInfoSingleFile.name = QString::fromUtf8(info.value("name").toByteArray());
+ metaInfoSingleFile.pieceLength = info.value("piece length").toInt();
+
+ QByteArray pieces = info.value("pieces").toByteArray();
+ for (int i = 0; i < pieces.size(); i += 20)
+ metaInfoSingleFile.sha1Sums << pieces.mid(i, 20);
+ }
+
+ metaInfoAnnounce = QString::fromUtf8(dict.value("announce").toByteArray());
+
+ if (dict.contains("announce-list")) {
+ // ### unimplemented
+ }
+
+ if (dict.contains("creation date"))
+ metaInfoCreationDate.setTime_t(dict.value("creation date").toInt());
+ if (dict.contains("comment"))
+ metaInfoComment = QString::fromUtf8(dict.value("comment").toByteArray());
+ if (dict.contains("created by"))
+ metaInfoCreatedBy = QString::fromUtf8(dict.value("created by").toByteArray());
+
+ return true;
+}
+
+QByteArray MetaInfo::infoValue() const
+{
+ return infoData;
+}
+
+QString MetaInfo::errorString() const
+{
+ return errString;
+}
+
+MetaInfo::FileForm MetaInfo::fileForm() const
+{
+ return metaInfoFileForm;
+}
+
+QString MetaInfo::announceUrl() const
+{
+ return metaInfoAnnounce;
+}
+
+QStringList MetaInfo::announceList() const
+{
+ return metaInfoAnnounceList;
+}
+
+QDateTime MetaInfo::creationDate() const
+{
+ return metaInfoCreationDate;
+}
+
+QString MetaInfo::comment() const
+{
+ return metaInfoComment;
+}
+
+QString MetaInfo::createdBy() const
+{
+ return metaInfoCreatedBy;
+}
+
+MetaInfoSingleFile MetaInfo::singleFile() const
+{
+ return metaInfoSingleFile;
+}
+
+QList<MetaInfoMultiFile> MetaInfo::multiFiles() const
+{
+ return metaInfoMultiFiles;
+}
+
+QString MetaInfo::name() const
+{
+ return metaInfoName;
+}
+
+int MetaInfo::pieceLength() const
+{
+ return metaInfoPieceLength;
+}
+
+QList<QByteArray> MetaInfo::sha1Sums() const
+{
+ return metaInfoSha1Sums;
+}
+
+qint64 MetaInfo::totalSize() const
+{
+ if (fileForm() == SingleFileForm)
+ return singleFile().length;
+
+ qint64 size = 0;
+ foreach (MetaInfoMultiFile file, multiFiles())
+ size += file.length;
+ return size;
+}
diff --git a/examples/network/torrent/metainfo.h b/examples/network/torrent/metainfo.h
new file mode 100644
index 0000000000..afa824d74b
--- /dev/null
+++ b/examples/network/torrent/metainfo.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef METAINFO_H
+#define METAINFO_H
+
+#include <QByteArray>
+#include <QDateTime>
+#include <QList>
+#include <QMap>
+#include <QString>
+#include <QStringList>
+#include <QVariant>
+
+struct MetaInfoSingleFile
+{
+ qint64 length;
+ QByteArray md5sum;
+ QString name;
+ int pieceLength;
+ QList<QByteArray> sha1Sums;
+};
+
+struct MetaInfoMultiFile
+{
+ qint64 length;
+ QByteArray md5sum;
+ QString path;
+};
+
+class MetaInfo
+{
+public:
+ enum FileForm {
+ SingleFileForm,
+ MultiFileForm
+ };
+
+ MetaInfo();
+ void clear();
+
+ bool parse(const QByteArray &data);
+ QString errorString() const;
+
+ QByteArray infoValue() const;
+
+ FileForm fileForm() const;
+ QString announceUrl() const;
+ QStringList announceList() const;
+ QDateTime creationDate() const;
+ QString comment() const;
+ QString createdBy() const;
+
+ // For single file form
+ MetaInfoSingleFile singleFile() const;
+
+ // For multifile form
+ QList<MetaInfoMultiFile> multiFiles() const;
+ QString name() const;
+ int pieceLength() const;
+ QList<QByteArray> sha1Sums() const;
+
+ // Total size
+ qint64 totalSize() const;
+
+private:
+ QString errString;
+ QByteArray content;
+ QByteArray infoData;
+
+ FileForm metaInfoFileForm;
+ MetaInfoSingleFile metaInfoSingleFile;
+ QList<MetaInfoMultiFile> metaInfoMultiFiles;
+ QString metaInfoAnnounce;
+ QStringList metaInfoAnnounceList;
+ QDateTime metaInfoCreationDate;
+ QString metaInfoComment;
+ QString metaInfoCreatedBy;
+ QString metaInfoName;
+ int metaInfoPieceLength;
+ QList<QByteArray> metaInfoSha1Sums;
+};
+
+#endif
diff --git a/examples/network/torrent/peerwireclient.cpp b/examples/network/torrent/peerwireclient.cpp
new file mode 100644
index 0000000000..0d9580eeff
--- /dev/null
+++ b/examples/network/torrent/peerwireclient.cpp
@@ -0,0 +1,664 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "peerwireclient.h"
+
+#include <QHostAddress>
+#include <QTimerEvent>
+
+static const int PendingRequestTimeout = 60 * 1000;
+static const int ClientTimeout = 120 * 1000;
+static const int ConnectTimeout = 60 * 1000;
+static const int KeepAliveInterval = 30 * 1000;
+static const int RateControlTimerDelay = 2000;
+static const int MinimalHeaderSize = 48;
+static const int FullHeaderSize = 68;
+static const char ProtocolId[] = "BitTorrent protocol";
+static const char ProtocolIdSize = 19;
+
+// Reads a 32bit unsigned int from data in network order.
+static inline quint32 fromNetworkData(const char *data)
+{
+ const unsigned char *udata = (const unsigned char *)data;
+ return (quint32(udata[0]) << 24)
+ | (quint32(udata[1]) << 16)
+ | (quint32(udata[2]) << 8)
+ | (quint32(udata[3]));
+}
+
+// Writes a 32bit unsigned int from num to data in network order.
+static inline void toNetworkData(quint32 num, char *data)
+{
+ unsigned char *udata = (unsigned char *)data;
+ udata[3] = (num & 0xff);
+ udata[2] = (num & 0xff00) >> 8;
+ udata[1] = (num & 0xff0000) >> 16;
+ udata[0] = (num & 0xff000000) >> 24;
+}
+
+// Constructs an unconnected PeerWire client and starts the connect timer.
+PeerWireClient::PeerWireClient(const QByteArray &peerId, QObject *parent)
+ : QTcpSocket(parent), pendingBlockSizes(0),
+ pwState(ChokingPeer | ChokedByPeer), receivedHandShake(false), gotPeerId(false),
+ sentHandShake(false), nextPacketLength(-1), pendingRequestTimer(0), invalidateTimeout(false),
+ keepAliveTimer(0), torrentPeer(0)
+{
+ memset(uploadSpeedData, 0, sizeof(uploadSpeedData));
+ memset(downloadSpeedData, 0, sizeof(downloadSpeedData));
+
+ transferSpeedTimer = startTimer(RateControlTimerDelay);
+ timeoutTimer = startTimer(ConnectTimeout);
+ peerIdString = peerId;
+
+ connect(this, SIGNAL(readyRead()), this, SIGNAL(readyToTransfer()));
+ connect(this, SIGNAL(connected()), this, SIGNAL(readyToTransfer()));
+
+ connect(&socket, SIGNAL(connected()),
+ this, SIGNAL(connected()));
+ connect(&socket, SIGNAL(readyRead()),
+ this, SIGNAL(readyRead()));
+ connect(&socket, SIGNAL(disconnected()),
+ this, SIGNAL(disconnected()));
+ connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SIGNAL(error(QAbstractSocket::SocketError)));
+ connect(&socket, SIGNAL(bytesWritten(qint64)),
+ this, SIGNAL(bytesWritten(qint64)));
+ connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
+ this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+
+}
+
+// Registers the peer ID and SHA1 sum of the torrent, and initiates
+// the handshake.
+void PeerWireClient::initialize(const QByteArray &infoHash, int pieceCount)
+{
+ this->infoHash = infoHash;
+ peerPieces.resize(pieceCount);
+ if (!sentHandShake)
+ sendHandShake();
+}
+
+void PeerWireClient::setPeer(TorrentPeer *peer)
+{
+ torrentPeer = peer;
+}
+
+TorrentPeer *PeerWireClient::peer() const
+{
+ return torrentPeer;
+}
+
+QBitArray PeerWireClient::availablePieces() const
+{
+ return peerPieces;
+}
+
+QList<TorrentBlock> PeerWireClient::incomingBlocks() const
+{
+ return incoming;
+}
+
+// Sends a "choke" message, asking the peer to stop requesting blocks.
+void PeerWireClient::chokePeer()
+{
+ const char message[] = {0, 0, 0, 1, 0};
+ write(message, sizeof(message));
+ pwState |= ChokingPeer;
+
+ // After receiving a choke message, the peer will assume all
+ // pending requests are lost.
+ pendingBlocks.clear();
+ pendingBlockSizes = 0;
+}
+
+// Sends an "unchoke" message, allowing the peer to start/resume
+// requesting blocks.
+void PeerWireClient::unchokePeer()
+{
+ const char message[] = {0, 0, 0, 1, 1};
+ write(message, sizeof(message));
+ pwState &= ~ChokingPeer;
+
+ if (pendingRequestTimer)
+ killTimer(pendingRequestTimer);
+}
+
+// Sends a "keep-alive" message to prevent the peer from closing
+// the connection when there's no activity
+void PeerWireClient::sendKeepAlive()
+{
+ const char message[] = {0, 0, 0, 0};
+ write(message, sizeof(message));
+}
+
+// Sends an "interested" message, informing the peer that it has got
+// pieces that we'd like to download.
+void PeerWireClient::sendInterested()
+{
+ const char message[] = {0, 0, 0, 1, 2};
+ write(message, sizeof(message));
+ pwState |= InterestedInPeer;
+
+ // After telling the peer that we're interested, we expect to get
+ // unchoked within a certain timeframe; otherwise we'll drop the
+ // connection.
+ if (pendingRequestTimer)
+ killTimer(pendingRequestTimer);
+ pendingRequestTimer = startTimer(PendingRequestTimeout);
+}
+
+// Sends a "not interested" message, informing the peer that it does
+// not have any pieces that we'd like to download.
+void PeerWireClient::sendNotInterested()
+{
+ const char message[] = {0, 0, 0, 1, 3};
+ write(message, sizeof(message));
+ pwState &= ~InterestedInPeer;
+}
+
+// Sends a piece notification / a "have" message, informing the peer
+// that we have just downloaded a new piece.
+void PeerWireClient::sendPieceNotification(int piece)
+{
+ if (!sentHandShake)
+ sendHandShake();
+
+ char message[] = {0, 0, 0, 5, 4, 0, 0, 0, 0};
+ toNetworkData(piece, &message[5]);
+ write(message, sizeof(message));
+}
+
+// Sends the complete list of pieces that we have downloaded.
+void PeerWireClient::sendPieceList(const QBitArray &bitField)
+{
+ // The bitfield message may only be sent immediately after the
+ // handshaking sequence is completed, and before any other
+ // messages are sent.
+ if (!sentHandShake)
+ sendHandShake();
+
+ // Don't send the bitfield if it's all zeros.
+ if (bitField.count(true) == 0)
+ return;
+
+ int bitFieldSize = bitField.size();
+ int size = (bitFieldSize + 7) / 8;
+ QByteArray bits(size, '\0');
+ for (int i = 0; i < bitFieldSize; ++i) {
+ if (bitField.testBit(i)) {
+ quint32 byte = quint32(i) / 8;
+ quint32 bit = quint32(i) % 8;
+ bits[byte] = uchar(bits.at(byte)) | (1 << (7 - bit));
+ }
+ }
+
+ char message[] = {0, 0, 0, 1, 5};
+ toNetworkData(bits.size() + 1, &message[0]);
+ write(message, sizeof(message));
+ write(bits);
+}
+
+// Sends a request for a block.
+void PeerWireClient::requestBlock(int piece, int offset, int length)
+{
+ char message[] = {0, 0, 0, 1, 6};
+ toNetworkData(13, &message[0]);
+ write(message, sizeof(message));
+
+ char numbers[4 * 3];
+ toNetworkData(piece, &numbers[0]);
+ toNetworkData(offset, &numbers[4]);
+ toNetworkData(length, &numbers[8]);
+ write(numbers, sizeof(numbers));
+
+ incoming << TorrentBlock(piece, offset, length);
+
+ // After requesting a block, we expect the block to be sent by the
+ // other peer within a certain number of seconds. Otherwise, we
+ // drop the connection.
+ if (pendingRequestTimer)
+ killTimer(pendingRequestTimer);
+ pendingRequestTimer = startTimer(PendingRequestTimeout);
+}
+
+// Cancels a request for a block.
+void PeerWireClient::cancelRequest(int piece, int offset, int length)
+{
+ char message[] = {0, 0, 0, 1, 8};
+ toNetworkData(13, &message[0]);
+ write(message, sizeof(message));
+
+ char numbers[4 * 3];
+ toNetworkData(piece, &numbers[0]);
+ toNetworkData(offset, &numbers[4]);
+ toNetworkData(length, &numbers[8]);
+ write(numbers, sizeof(numbers));
+
+ incoming.removeAll(TorrentBlock(piece, offset, length));
+}
+
+// Sends a block to the peer.
+void PeerWireClient::sendBlock(int piece, int offset, const QByteArray &data)
+{
+ QByteArray block;
+
+ char message[] = {0, 0, 0, 1, 7};
+ toNetworkData(9 + data.size(), &message[0]);
+ block += QByteArray(message, sizeof(message));
+
+ char numbers[4 * 2];
+ toNetworkData(piece, &numbers[0]);
+ toNetworkData(offset, &numbers[4]);
+ block += QByteArray(numbers, sizeof(numbers));
+ block += data;
+
+ BlockInfo blockInfo;
+ blockInfo.pieceIndex = piece;
+ blockInfo.offset = offset;
+ blockInfo.length = data.size();
+ blockInfo.block = block;
+
+ pendingBlocks << blockInfo;
+ pendingBlockSizes += block.size();
+
+ if (pendingBlockSizes > 32 * 16384) {
+ chokePeer();
+ unchokePeer();
+ return;
+ }
+ emit readyToTransfer();
+}
+
+// Attempts to write 'bytes' bytes to the socket from the buffer.
+// This is used by RateController, which precisely controls how much
+// each client can write.
+qint64 PeerWireClient::writeToSocket(qint64 bytes)
+{
+ qint64 totalWritten = 0;
+ do {
+ if (outgoingBuffer.isEmpty() && !pendingBlocks.isEmpty()) {
+ BlockInfo block = pendingBlocks.takeFirst();
+ pendingBlockSizes -= block.length;
+ outgoingBuffer += block.block;
+ }
+ qint64 written = socket.write(outgoingBuffer.constData(),
+ qMin<qint64>(bytes - totalWritten, outgoingBuffer.size()));
+ if (written <= 0)
+ return totalWritten ? totalWritten : written;
+
+ totalWritten += written;
+ uploadSpeedData[0] += written;
+ outgoingBuffer.remove(0, written);
+ } while (totalWritten < bytes && (!outgoingBuffer.isEmpty() || !pendingBlocks.isEmpty()));
+
+ return totalWritten;
+}
+
+// Attempts to read at most 'bytes' bytes from the socket.
+qint64 PeerWireClient::readFromSocket(qint64 bytes)
+{
+ char buffer[1024];
+ qint64 totalRead = 0;
+ do {
+ qint64 bytesRead = socket.read(buffer, qMin<qint64>(sizeof(buffer), bytes - totalRead));
+ if (bytesRead <= 0)
+ break;
+ qint64 oldSize = incomingBuffer.size();
+ incomingBuffer.resize(oldSize + bytesRead);
+ memcpy(incomingBuffer.data() + oldSize, buffer, bytesRead);
+
+ totalRead += bytesRead;
+ } while (totalRead < bytes);
+
+ if (totalRead > 0) {
+ downloadSpeedData[0] += totalRead;
+ emit bytesReceived(totalRead);
+ processIncomingData();
+ }
+ return totalRead;
+}
+
+// Returns the average number of bytes per second this client is
+// downloading.
+qint64 PeerWireClient::downloadSpeed() const
+{
+ qint64 sum = 0;
+ for (unsigned int i = 0; i < sizeof(downloadSpeedData) / sizeof(qint64); ++i)
+ sum += downloadSpeedData[i];
+ return sum / (8 * 2);
+}
+
+// Returns the average number of bytes per second this client is
+// uploading.
+qint64 PeerWireClient::uploadSpeed() const
+{
+ qint64 sum = 0;
+ for (unsigned int i = 0; i < sizeof(uploadSpeedData) / sizeof(qint64); ++i)
+ sum += uploadSpeedData[i];
+ return sum / (8 * 2);
+}
+
+void PeerWireClient::setReadBufferSize(int size)
+{
+ socket.setReadBufferSize(size);
+}
+
+bool PeerWireClient::canTransferMore() const
+{
+ return bytesAvailable() > 0 || socket.bytesAvailable() > 0
+ || !outgoingBuffer.isEmpty() || !pendingBlocks.isEmpty();
+}
+
+void PeerWireClient::connectToHostImplementation(const QString &hostName,
+ quint16 port, OpenMode openMode)
+
+{
+ setOpenMode(openMode);
+ socket.connectToHost(hostName, port, openMode);
+}
+
+void PeerWireClient::diconnectFromHostImplementation()
+{
+ socket.disconnectFromHost();
+}
+
+void PeerWireClient::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == transferSpeedTimer) {
+ // Rotate the upload / download records.
+ for (int i = 6; i >= 0; --i) {
+ uploadSpeedData[i + 1] = uploadSpeedData[i];
+ downloadSpeedData[i + 1] = downloadSpeedData[i];
+ }
+ uploadSpeedData[0] = 0;
+ downloadSpeedData[0] = 0;
+ } else if (event->timerId() == timeoutTimer) {
+ // Disconnect if we timed out; otherwise the timeout is
+ // restarted.
+ if (invalidateTimeout) {
+ invalidateTimeout = false;
+ } else {
+ abort();
+ emit infoHashReceived(QByteArray());
+ }
+ } else if (event->timerId() == pendingRequestTimer) {
+ abort();
+ } else if (event->timerId() == keepAliveTimer) {
+ sendKeepAlive();
+ }
+ QTcpSocket::timerEvent(event);
+}
+
+// Sends the handshake to the peer.
+void PeerWireClient::sendHandShake()
+{
+ sentHandShake = true;
+
+ // Restart the timeout
+ if (timeoutTimer)
+ killTimer(timeoutTimer);
+ timeoutTimer = startTimer(ClientTimeout);
+
+ // Write the 68 byte PeerWire handshake.
+ write(&ProtocolIdSize, 1);
+ write(ProtocolId, ProtocolIdSize);
+ write(QByteArray(8, '\0'));
+ write(infoHash);
+ write(peerIdString);
+}
+
+void PeerWireClient::processIncomingData()
+{
+ invalidateTimeout = true;
+ if (!receivedHandShake) {
+ // Check that we received enough data
+ if (bytesAvailable() < MinimalHeaderSize)
+ return;
+
+ // Sanity check the protocol ID
+ QByteArray id = read(ProtocolIdSize + 1);
+ if (id.at(0) != ProtocolIdSize || !id.mid(1).startsWith(ProtocolId)) {
+ abort();
+ return;
+ }
+
+ // Discard 8 reserved bytes, then read the info hash and peer ID
+ (void) read(8);
+
+ // Read infoHash
+ QByteArray peerInfoHash = read(20);
+ if (!infoHash.isEmpty() && peerInfoHash != infoHash) {
+ abort();
+ return;
+ }
+
+ emit infoHashReceived(peerInfoHash);
+ if (infoHash.isEmpty()) {
+ abort();
+ return;
+ }
+
+ // Send handshake
+ if (!sentHandShake)
+ sendHandShake();
+ receivedHandShake = true;
+ }
+
+ // Handle delayed peer id arrival
+ if (!gotPeerId) {
+ if (bytesAvailable() < 20)
+ return;
+ gotPeerId = true;
+ if (read(20) == peerIdString) {
+ // We connected to ourself
+ abort();
+ return;
+ }
+ }
+
+ // Initialize keep-alive timer
+ if (!keepAliveTimer)
+ keepAliveTimer = startTimer(KeepAliveInterval);
+
+ do {
+ // Find the packet length
+ if (nextPacketLength == -1) {
+ if (bytesAvailable() < 4)
+ return;
+
+ char tmp[4];
+ read(tmp, sizeof(tmp));
+ nextPacketLength = fromNetworkData(tmp);
+
+ if (nextPacketLength < 0 || nextPacketLength > 200000) {
+ // Prevent DoS
+ abort();
+ return;
+ }
+ }
+
+ // KeepAlive
+ if (nextPacketLength == 0) {
+ nextPacketLength = -1;
+ continue;
+ }
+
+ // Wait with parsing until the whole packet has been received
+ if (bytesAvailable() < nextPacketLength)
+ return;
+
+ // Read the packet
+ QByteArray packet = read(nextPacketLength);
+ if (packet.size() != nextPacketLength) {
+ abort();
+ return;
+ }
+
+ switch (packet.at(0)) {
+ case ChokePacket:
+ // We have been choked.
+ pwState |= ChokedByPeer;
+ incoming.clear();
+ if (pendingRequestTimer)
+ killTimer(pendingRequestTimer);
+ emit choked();
+ break;
+ case UnchokePacket:
+ // We have been unchoked.
+ pwState &= ~ChokedByPeer;
+ emit unchoked();
+ break;
+ case InterestedPacket:
+ // The peer is interested in downloading.
+ pwState |= PeerIsInterested;
+ emit interested();
+ break;
+ case NotInterestedPacket:
+ // The peer is not interested in downloading.
+ pwState &= ~PeerIsInterested;
+ emit notInterested();
+ break;
+ case HavePacket: {
+ // The peer has a new piece available.
+ quint32 index = fromNetworkData(&packet.data()[1]);
+ if (index < quint32(peerPieces.size())) {
+ // Only accept indexes within the valid range.
+ peerPieces.setBit(int(index));
+ }
+ emit piecesAvailable(availablePieces());
+ break;
+ }
+ case BitFieldPacket:
+ // The peer has the following pieces available.
+ for (int i = 1; i < packet.size(); ++i) {
+ for (int bit = 0; bit < 8; ++bit) {
+ if (packet.at(i) & (1 << (7 - bit))) {
+ int bitIndex = int(((i - 1) * 8) + bit);
+ if (bitIndex >= 0 && bitIndex < peerPieces.size()) {
+ // Occasionally, broken clients claim to have
+ // pieces whose index is outside the valid range.
+ // The most common mistake is the index == size
+ // case.
+ peerPieces.setBit(bitIndex);
+ }
+ }
+ }
+ }
+ emit piecesAvailable(availablePieces());
+ break;
+ case RequestPacket: {
+ // The peer requests a block.
+ quint32 index = fromNetworkData(&packet.data()[1]);
+ quint32 begin = fromNetworkData(&packet.data()[5]);
+ quint32 length = fromNetworkData(&packet.data()[9]);
+ emit blockRequested(int(index), int(begin), int(length));
+ break;
+ }
+ case PiecePacket: {
+ int index = int(fromNetworkData(&packet.data()[1]));
+ int begin = int(fromNetworkData(&packet.data()[5]));
+
+ incoming.removeAll(TorrentBlock(index, begin, packet.size() - 9));
+
+ // The peer sends a block.
+ emit blockReceived(index, begin, packet.mid(9));
+
+ // Kill the pending block timer.
+ if (pendingRequestTimer) {
+ killTimer(pendingRequestTimer);
+ pendingRequestTimer = 0;
+ }
+ break;
+ }
+ case CancelPacket: {
+ // The peer cancels a block request.
+ quint32 index = fromNetworkData(&packet.data()[1]);
+ quint32 begin = fromNetworkData(&packet.data()[5]);
+ quint32 length = fromNetworkData(&packet.data()[9]);
+ for (int i = 0; i < pendingBlocks.size(); ++i) {
+ const BlockInfo &blockInfo = pendingBlocks.at(i);
+ if (blockInfo.pieceIndex == int(index)
+ && blockInfo.offset == int(begin)
+ && blockInfo.length == int(length)) {
+ pendingBlocks.removeAt(i);
+ break;
+ }
+ }
+ break;
+ }
+ default:
+ // Unsupported packet type; just ignore it.
+ break;
+ }
+ nextPacketLength = -1;
+ } while (bytesAvailable() > 0);
+}
+
+void PeerWireClient::socketStateChanged(QAbstractSocket::SocketState state)
+{
+ setLocalAddress(socket.localAddress());
+ setLocalPort(socket.localPort());
+ setPeerName(socket.peerName());
+ setPeerAddress(socket.peerAddress());
+ setPeerPort(socket.peerPort());
+ setSocketState(state);
+}
+
+qint64 PeerWireClient::readData(char *data, qint64 size)
+{
+ int n = qMin<int>(size, incomingBuffer.size());
+ memcpy(data, incomingBuffer.constData(), n);
+ incomingBuffer.remove(0, n);
+ return n;
+}
+
+qint64 PeerWireClient::readLineData(char *data, qint64 maxlen)
+{
+ return QIODevice::readLineData(data, maxlen);
+}
+
+qint64 PeerWireClient::writeData(const char *data, qint64 size)
+{
+ int oldSize = outgoingBuffer.size();
+ outgoingBuffer.resize(oldSize + size);
+ memcpy(outgoingBuffer.data() + oldSize, data, size);
+ emit readyToTransfer();
+ return size;
+}
diff --git a/examples/network/torrent/peerwireclient.h b/examples/network/torrent/peerwireclient.h
new file mode 100644
index 0000000000..b8f8cb56e5
--- /dev/null
+++ b/examples/network/torrent/peerwireclient.h
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PEERWIRECLIENT_H
+#define PEERWIRECLIENT_H
+
+#include <QBitArray>
+#include <QList>
+#include <QTcpSocket>
+
+QT_BEGIN_NAMESPACE
+class QHostAddress;
+class QTimerEvent;
+QT_END_NAMESPACE
+class TorrentPeer;
+
+struct TorrentBlock
+{
+ inline TorrentBlock(int p, int o, int l)
+ : pieceIndex(p), offset(o), length(l)
+ {
+ }
+ inline bool operator==(const TorrentBlock &other) const
+ {
+ return pieceIndex == other.pieceIndex
+ && offset == other.offset
+ && length == other.length;
+ }
+
+ int pieceIndex;
+ int offset;
+ int length;
+};
+
+class PeerWireClient : public QTcpSocket
+{
+ Q_OBJECT
+
+public:
+ enum PeerWireStateFlag {
+ ChokingPeer = 0x1,
+ InterestedInPeer = 0x2,
+ ChokedByPeer = 0x4,
+ PeerIsInterested = 0x8
+ };
+ Q_DECLARE_FLAGS(PeerWireState, PeerWireStateFlag)
+
+ PeerWireClient(const QByteArray &peerId, QObject *parent = 0);
+ void initialize(const QByteArray &infoHash, int pieceCount);
+
+ void setPeer(TorrentPeer *peer);
+ TorrentPeer *peer() const;
+
+ // State
+ inline PeerWireState peerWireState() const { return pwState; }
+ QBitArray availablePieces() const;
+ QList<TorrentBlock> incomingBlocks() const;
+
+ // Protocol
+ void chokePeer();
+ void unchokePeer();
+ void sendInterested();
+ void sendKeepAlive();
+ void sendNotInterested();
+ void sendPieceNotification(int piece);
+ void sendPieceList(const QBitArray &bitField);
+ void requestBlock(int piece, int offset, int length);
+ void cancelRequest(int piece, int offset, int length);
+ void sendBlock(int piece, int offset, const QByteArray &data);
+
+ // Rate control
+ qint64 writeToSocket(qint64 bytes);
+ qint64 readFromSocket(qint64 bytes);
+ qint64 downloadSpeed() const;
+ qint64 uploadSpeed() const;
+
+ bool canTransferMore() const;
+ qint64 bytesAvailable() const { return incomingBuffer.size() + QTcpSocket::bytesAvailable(); }
+ qint64 socketBytesAvailable() const { return socket.bytesAvailable(); }
+ qint64 socketBytesToWrite() const { return socket.bytesToWrite(); }
+
+ void setReadBufferSize(int size);
+
+signals:
+ void infoHashReceived(const QByteArray &infoHash);
+ void readyToTransfer();
+
+ void choked();
+ void unchoked();
+ void interested();
+ void notInterested();
+
+ void piecesAvailable(const QBitArray &pieces);
+ void blockRequested(int pieceIndex, int begin, int length);
+ void blockReceived(int pieceIndex, int begin, const QByteArray &data);
+
+ void bytesReceived(qint64 size);
+
+protected slots:
+ void connectToHostImplementation(const QString &hostName,
+ quint16 port, OpenMode openMode = ReadWrite);
+ void diconnectFromHostImplementation();
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+ qint64 readData(char *data, qint64 maxlen);
+ qint64 readLineData(char *data, qint64 maxlen);
+ qint64 writeData(const char *data, qint64 len);
+
+private slots:
+ void sendHandShake();
+ void processIncomingData();
+ void socketStateChanged(QAbstractSocket::SocketState state);
+
+private:
+ // Data waiting to be read/written
+ QByteArray incomingBuffer;
+ QByteArray outgoingBuffer;
+
+ struct BlockInfo {
+ int pieceIndex;
+ int offset;
+ int length;
+ QByteArray block;
+ };
+ QList<BlockInfo> pendingBlocks;
+ int pendingBlockSizes;
+ QList<TorrentBlock> incoming;
+
+ enum PacketType {
+ ChokePacket = 0,
+ UnchokePacket = 1,
+ InterestedPacket = 2,
+ NotInterestedPacket = 3,
+ HavePacket = 4,
+ BitFieldPacket = 5,
+ RequestPacket = 6,
+ PiecePacket = 7,
+ CancelPacket = 8
+ };
+
+ // State
+ PeerWireState pwState;
+ bool receivedHandShake;
+ bool gotPeerId;
+ bool sentHandShake;
+ int nextPacketLength;
+
+ // Upload/download speed records
+ qint64 uploadSpeedData[8];
+ qint64 downloadSpeedData[8];
+ int transferSpeedTimer;
+
+ // Timeout handling
+ int timeoutTimer;
+ int pendingRequestTimer;
+ bool invalidateTimeout;
+ int keepAliveTimer;
+
+ // Checksum, peer ID and set of available pieces
+ QByteArray infoHash;
+ QByteArray peerIdString;
+ QBitArray peerPieces;
+ TorrentPeer *torrentPeer;
+
+ QTcpSocket socket;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(PeerWireClient::PeerWireState)
+
+#endif
diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp
new file mode 100644
index 0000000000..47cf177ccb
--- /dev/null
+++ b/examples/network/torrent/ratecontroller.cpp
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "peerwireclient.h"
+#include "ratecontroller.h"
+
+#include <QtCore>
+
+Q_GLOBAL_STATIC(RateController, rateController)
+
+RateController *RateController::instance()
+{
+ return rateController();
+}
+
+void RateController::addSocket(PeerWireClient *socket)
+{
+ connect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
+ socket->setReadBufferSize(downLimit * 4);
+ sockets << socket;
+ scheduleTransfer();
+}
+
+void RateController::removeSocket(PeerWireClient *socket)
+{
+ disconnect(socket, SIGNAL(readyToTransfer()), this, SLOT(scheduleTransfer()));
+ socket->setReadBufferSize(0);
+ sockets.remove(socket);
+}
+
+void RateController::setDownloadLimit(int bytesPerSecond)
+{
+ downLimit = bytesPerSecond;
+ foreach (PeerWireClient *socket, sockets)
+ socket->setReadBufferSize(downLimit * 4);
+}
+
+void RateController::scheduleTransfer()
+{
+ if (transferScheduled)
+ return;
+ transferScheduled = true;
+ QTimer::singleShot(50, this, SLOT(transfer()));
+}
+
+void RateController::transfer()
+{
+ transferScheduled = false;
+ if (sockets.isEmpty())
+ return;
+
+ int msecs = 1000;
+ if (!stopWatch.isNull())
+ msecs = qMin(msecs, stopWatch.elapsed());
+
+ qint64 bytesToWrite = (upLimit * msecs) / 1000;
+ qint64 bytesToRead = (downLimit * msecs) / 1000;
+ if (bytesToWrite == 0 && bytesToRead == 0) {
+ scheduleTransfer();
+ return;
+ }
+
+ QSet<PeerWireClient *> pendingSockets;
+ foreach (PeerWireClient *client, sockets) {
+ if (client->canTransferMore())
+ pendingSockets << client;
+ }
+ if (pendingSockets.isEmpty())
+ return;
+
+ stopWatch.start();
+
+ bool canTransferMore;
+ do {
+ canTransferMore = false;
+ qint64 writeChunk = qMax<qint64>(1, bytesToWrite / pendingSockets.size());
+ qint64 readChunk = qMax<qint64>(1, bytesToRead / pendingSockets.size());
+
+ QSetIterator<PeerWireClient *> it(pendingSockets);
+ while (it.hasNext() && (bytesToWrite > 0 || bytesToRead > 0)) {
+ PeerWireClient *socket = it.next();
+ if (socket->state() != QAbstractSocket::ConnectedState) {
+ pendingSockets.remove(socket);
+ continue;
+ }
+
+ bool dataTransferred = false;
+ qint64 available = qMin<qint64>(socket->socketBytesAvailable(), readChunk);
+ if (available > 0) {
+ qint64 readBytes = socket->readFromSocket(qMin<qint64>(available, bytesToRead));
+ if (readBytes > 0) {
+ bytesToRead -= readBytes;
+ dataTransferred = true;
+ }
+ }
+
+ if (upLimit * 2 > socket->bytesToWrite()) {
+ qint64 chunkSize = qMin<qint64>(writeChunk, bytesToWrite);
+ qint64 toWrite = qMin(upLimit * 2 - socket->bytesToWrite(), chunkSize);
+ if (toWrite > 0) {
+ qint64 writtenBytes = socket->writeToSocket(toWrite);
+ if (writtenBytes > 0) {
+ bytesToWrite -= writtenBytes;
+ dataTransferred = true;
+ }
+ }
+ }
+
+ if (dataTransferred && socket->canTransferMore())
+ canTransferMore = true;
+ else
+ pendingSockets.remove(socket);
+ }
+ } while (canTransferMore && (bytesToWrite > 0 || bytesToRead > 0) && !pendingSockets.isEmpty());
+
+ if (canTransferMore || bytesToWrite == 0 || bytesToRead == 0)
+ scheduleTransfer();
+}
diff --git a/examples/network/torrent/ratecontroller.h b/examples/network/torrent/ratecontroller.h
new file mode 100644
index 0000000000..4949abb641
--- /dev/null
+++ b/examples/network/torrent/ratecontroller.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RATECONTROLLER_H
+#define RATECONTROLLER_H
+
+#include <QObject>
+#include <QSet>
+#include <QTime>
+
+class PeerWireClient;
+
+class RateController : public QObject
+{
+ Q_OBJECT
+
+public:
+ inline RateController(QObject *parent = 0)
+ : QObject(parent), transferScheduled(false) { }
+ static RateController *instance();
+
+ void addSocket(PeerWireClient *socket);
+ void removeSocket(PeerWireClient *socket);
+
+ inline int uploadLimit() const { return upLimit; }
+ inline int downloadLimit() const { return downLimit; }
+ inline void setUploadLimit(int bytesPerSecond) { upLimit = bytesPerSecond; }
+ void setDownloadLimit(int bytesPerSecond);
+
+public slots:
+ void transfer();
+ void scheduleTransfer();
+
+private:
+ QTime stopWatch;
+ QSet<PeerWireClient *> sockets;
+ int upLimit;
+ int downLimit;
+ bool transferScheduled;
+};
+
+#endif
diff --git a/examples/network/torrent/torrent.pro b/examples/network/torrent/torrent.pro
new file mode 100644
index 0000000000..a9acf7bbc0
--- /dev/null
+++ b/examples/network/torrent/torrent.pro
@@ -0,0 +1,39 @@
+HEADERS += addtorrentdialog.h \
+ bencodeparser.h \
+ connectionmanager.h \
+ mainwindow.h \
+ metainfo.h \
+ peerwireclient.h \
+ ratecontroller.h \
+ filemanager.h \
+ torrentclient.h \
+ torrentserver.h \
+ trackerclient.h
+
+SOURCES += main.cpp \
+ addtorrentdialog.cpp \
+ bencodeparser.cpp \
+ connectionmanager.cpp \
+ mainwindow.cpp \
+ metainfo.cpp \
+ peerwireclient.cpp \
+ ratecontroller.cpp \
+ filemanager.cpp \
+ torrentclient.cpp \
+ torrentserver.cpp \
+ trackerclient.cpp
+
+# Forms and resources
+FORMS += forms/addtorrentform.ui
+RESOURCES += icons.qrc
+
+QT += network
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/torrent
+sources.files = $$SOURCES $$HEADERS $$RESOURCES torrent.pro *.torrent
+sources.files += icons forms 3rdparty
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/network/torrent
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
new file mode 100644
index 0000000000..3df1bb886f
--- /dev/null
+++ b/examples/network/torrent/torrentclient.cpp
@@ -0,0 +1,1528 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "connectionmanager.h"
+#include "filemanager.h"
+#include "metainfo.h"
+#include "torrentclient.h"
+#include "torrentserver.h"
+#include "trackerclient.h"
+#include "peerwireclient.h"
+#include "ratecontroller.h"
+
+#include <QtCore>
+#include <QNetworkInterface>
+
+// These constants could also be configurable by the user.
+static const int ServerMinPort = 6881;
+static const int ServerMaxPort = /* 6889 */ 7000;
+static const int BlockSize = 16384;
+static const int MaxBlocksInProgress = 5;
+static const int MaxBlocksInMultiMode = 2;
+static const int MaxConnectionPerPeer = 1;
+static const int RateControlWindowLength = 10;
+static const int RateControlTimerDelay = 1000;
+static const int MinimumTimeBeforeRevisit = 30;
+static const int MaxUploads = 4;
+static const int UploadScheduleInterval = 10000;
+static const int EndGamePieces = 5;
+
+class TorrentPiece {
+public:
+ int index;
+ int length;
+ QBitArray completedBlocks;
+ QBitArray requestedBlocks;
+ bool inProgress;
+};
+
+class TorrentClientPrivate
+{
+public:
+ TorrentClientPrivate(TorrentClient *qq);
+
+ // State / error
+ void setError(TorrentClient::Error error);
+ void setState(TorrentClient::State state);
+ TorrentClient::Error error;
+ TorrentClient::State state;
+ QString errorString;
+ QString stateString;
+
+ // Where to save data
+ QString destinationFolder;
+ MetaInfo metaInfo;
+
+ // Announce tracker and file manager
+ QByteArray peerId;
+ QByteArray infoHash;
+ TrackerClient trackerClient;
+ FileManager fileManager;
+
+ // Connections
+ QList<PeerWireClient *> connections;
+ QList<TorrentPeer *> peers;
+ bool schedulerCalled;
+ void callScheduler();
+ bool connectingToClients;
+ void callPeerConnector();
+ int uploadScheduleTimer;
+
+ // Pieces
+ QMap<int, PeerWireClient *> readIds;
+ QMultiMap<PeerWireClient *, TorrentPiece *> payloads;
+ QMap<int, TorrentPiece *> pendingPieces;
+ QBitArray completedPieces;
+ QBitArray incompletePieces;
+ int pieceCount;
+
+ // Progress
+ int lastProgressValue;
+ qint64 downloadedBytes;
+ qint64 uploadedBytes;
+ int downloadRate[RateControlWindowLength];
+ int uploadRate[RateControlWindowLength];
+ int transferRateTimer;
+
+ TorrentClient *q;
+};
+
+TorrentClientPrivate::TorrentClientPrivate(TorrentClient *qq)
+ : trackerClient(qq), q(qq)
+{
+ error = TorrentClient::UnknownError;
+ state = TorrentClient::Idle;
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "Unknown error");
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Idle");
+ schedulerCalled = false;
+ connectingToClients = false;
+ uploadScheduleTimer = 0;
+ lastProgressValue = -1;
+ pieceCount = 0;
+ downloadedBytes = 0;
+ uploadedBytes = 0;
+ memset(downloadRate, 0, sizeof(downloadRate));
+ memset(uploadRate, 0, sizeof(uploadRate));
+ transferRateTimer = 0;
+}
+
+void TorrentClientPrivate::setError(TorrentClient::Error errorCode)
+{
+ this->error = errorCode;
+ switch (error) {
+ case TorrentClient::UnknownError:
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "Unknown error");
+ break;
+ case TorrentClient::TorrentParseError:
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "Invalid torrent data");
+ break;
+ case TorrentClient::InvalidTrackerError:
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "Unable to connect to tracker");
+ break;
+ case TorrentClient::FileError:
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "File error");
+ break;
+ case TorrentClient::ServerError:
+ errorString = QT_TRANSLATE_NOOP(TorrentClient, "Unable to initialize server");
+ break;
+ }
+ emit q->error(errorCode);
+}
+
+void TorrentClientPrivate::setState(TorrentClient::State state)
+{
+ this->state = state;
+ switch (state) {
+ case TorrentClient::Idle:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Idle");
+ break;
+ case TorrentClient::Paused:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Paused");
+ break;
+ case TorrentClient::Stopping:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Stopping");
+ break;
+ case TorrentClient::Preparing:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Preparing");
+ break;
+ case TorrentClient::Searching:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Searching");
+ break;
+ case TorrentClient::Connecting:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Connecting");
+ break;
+ case TorrentClient::WarmingUp:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Warming up");
+ break;
+ case TorrentClient::Downloading:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Downloading");
+ break;
+ case TorrentClient::Endgame:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Finishing");
+ break;
+ case TorrentClient::Seeding:
+ stateString = QT_TRANSLATE_NOOP(TorrentClient, "Seeding");
+ break;
+ }
+ emit q->stateChanged(state);
+}
+
+void TorrentClientPrivate::callScheduler()
+{
+ if (!schedulerCalled) {
+ schedulerCalled = true;
+ QMetaObject::invokeMethod(q, "scheduleDownloads", Qt::QueuedConnection);
+ }
+}
+
+void TorrentClientPrivate::callPeerConnector()
+{
+ if (!connectingToClients) {
+ connectingToClients = true;
+ QTimer::singleShot(10000, q, SLOT(connectToPeers()));
+ }
+}
+
+TorrentClient::TorrentClient(QObject *parent)
+ : QObject(parent), d(new TorrentClientPrivate(this))
+{
+ // Connect the file manager
+ connect(&d->fileManager, SIGNAL(dataRead(int,int,int,QByteArray)),
+ this, SLOT(sendToPeer(int,int,int,QByteArray)));
+ connect(&d->fileManager, SIGNAL(verificationProgress(int)),
+ this, SLOT(updateProgress(int)));
+ connect(&d->fileManager, SIGNAL(verificationDone()),
+ this, SLOT(fullVerificationDone()));
+ connect(&d->fileManager, SIGNAL(pieceVerified(int,bool)),
+ this, SLOT(pieceVerified(int,bool)));
+ connect(&d->fileManager, SIGNAL(error()),
+ this, SLOT(handleFileError()));
+
+ // Connect the tracker client
+ connect(&d->trackerClient, SIGNAL(peerListUpdated(QList<TorrentPeer>)),
+ this, SLOT(addToPeerList(QList<TorrentPeer>)));
+ connect(&d->trackerClient, SIGNAL(stopped()),
+ this, SIGNAL(stopped()));
+}
+
+TorrentClient::~TorrentClient()
+{
+ qDeleteAll(d->peers);
+ qDeleteAll(d->pendingPieces);
+ delete d;
+}
+
+bool TorrentClient::setTorrent(const QString &fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly) || !setTorrent(file.readAll())) {
+ d->setError(TorrentParseError);
+ return false;
+ }
+ return true;
+}
+
+bool TorrentClient::setTorrent(const QByteArray &torrentData)
+{
+ if (!d->metaInfo.parse(torrentData)) {
+ d->setError(TorrentParseError);
+ return false;
+ }
+
+ // Calculate SHA1 hash of the "info" section in the torrent
+ QByteArray infoValue = d->metaInfo.infoValue();
+ d->infoHash = QCryptographicHash::hash(infoValue, QCryptographicHash::Sha1);
+
+ return true;
+}
+
+MetaInfo TorrentClient::metaInfo() const
+{
+ return d->metaInfo;
+}
+
+void TorrentClient::setDestinationFolder(const QString &directory)
+{
+ d->destinationFolder = directory;
+}
+
+QString TorrentClient::destinationFolder() const
+{
+ return d->destinationFolder;
+}
+
+void TorrentClient::setDumpedState(const QByteArray &dumpedState)
+{
+ // Recover partially completed pieces
+ QDataStream stream(dumpedState);
+
+ quint16 version = 0;
+ stream >> version;
+ if (version != 2)
+ return;
+
+ stream >> d->completedPieces;
+
+ while (!stream.atEnd()) {
+ int index;
+ int length;
+ QBitArray completed;
+ stream >> index >> length >> completed;
+ if (stream.status() != QDataStream::Ok) {
+ d->completedPieces.clear();
+ break;
+ }
+
+ TorrentPiece *piece = new TorrentPiece;
+ piece->index = index;
+ piece->length = length;
+ piece->completedBlocks = completed;
+ piece->requestedBlocks.resize(completed.size());
+ piece->inProgress = false;
+ d->pendingPieces[index] = piece;
+ }
+}
+
+QByteArray TorrentClient::dumpedState() const
+{
+ QByteArray partials;
+ QDataStream stream(&partials, QIODevice::WriteOnly);
+
+ stream << quint16(2);
+ stream << d->completedPieces;
+
+ // Save the state of all partially downloaded pieces into a format
+ // suitable for storing in settings.
+ QMap<int, TorrentPiece *>::ConstIterator it = d->pendingPieces.constBegin();
+ while (it != d->pendingPieces.constEnd()) {
+ TorrentPiece *piece = it.value();
+ if (blocksLeftForPiece(piece) > 0 && blocksLeftForPiece(piece) < piece->completedBlocks.size()) {
+ stream << piece->index;
+ stream << piece->length;
+ stream << piece->completedBlocks;
+ }
+ ++it;
+ }
+
+ return partials;
+}
+
+qint64 TorrentClient::progress() const
+{
+ return d->lastProgressValue;
+}
+
+void TorrentClient::setDownloadedBytes(qint64 bytes)
+{
+ d->downloadedBytes = bytes;
+}
+
+qint64 TorrentClient::downloadedBytes() const
+{
+ return d->downloadedBytes;
+}
+
+void TorrentClient::setUploadedBytes(qint64 bytes)
+{
+ d->uploadedBytes = bytes;
+}
+
+qint64 TorrentClient::uploadedBytes() const
+{
+ return d->uploadedBytes;
+}
+
+int TorrentClient::connectedPeerCount() const
+{
+ int tmp = 0;
+ foreach (PeerWireClient *client, d->connections) {
+ if (client->state() == QAbstractSocket::ConnectedState)
+ ++tmp;
+ }
+ return tmp;
+}
+
+int TorrentClient::seedCount() const
+{
+ int tmp = 0;
+ foreach (PeerWireClient *client, d->connections) {
+ if (client->availablePieces().count(true) == d->pieceCount)
+ ++tmp;
+ }
+ return tmp;
+}
+
+TorrentClient::State TorrentClient::state() const
+{
+ return d->state;
+}
+
+QString TorrentClient::stateString() const
+{
+ return d->stateString;
+}
+
+TorrentClient::Error TorrentClient::error() const
+{
+ return d->error;
+}
+
+QString TorrentClient::errorString() const
+{
+ return d->errorString;
+}
+
+QByteArray TorrentClient::peerId() const
+{
+ return d->peerId;
+}
+
+QByteArray TorrentClient::infoHash() const
+{
+ return d->infoHash;
+}
+
+void TorrentClient::start()
+{
+ if (d->state != Idle)
+ return;
+
+ TorrentServer::instance()->addClient(this);
+
+ // Initialize the file manager
+ d->setState(Preparing);
+ d->fileManager.setMetaInfo(d->metaInfo);
+ d->fileManager.setDestinationFolder(d->destinationFolder);
+ d->fileManager.setCompletedPieces(d->completedPieces);
+ d->fileManager.start(QThread::LowestPriority);
+ d->fileManager.startDataVerification();
+}
+
+void TorrentClient::stop()
+{
+ if (d->state == Stopping)
+ return;
+
+ TorrentServer::instance()->removeClient(this);
+
+ // Update the state
+ State oldState = d->state;
+ d->setState(Stopping);
+
+ // Stop the timer
+ if (d->transferRateTimer) {
+ killTimer(d->transferRateTimer);
+ d->transferRateTimer = 0;
+ }
+
+ // Abort all existing connections
+ foreach (PeerWireClient *client, d->connections) {
+ RateController::instance()->removeSocket(client);
+ ConnectionManager::instance()->removeConnection(client);
+ client->abort();
+ }
+ d->connections.clear();
+
+ // Perhaps stop the tracker
+ if (oldState > Preparing) {
+ d->trackerClient.stop();
+ } else {
+ d->setState(Idle);
+ emit stopped();
+ }
+}
+
+void TorrentClient::setPaused(bool paused)
+{
+ if (paused) {
+ // Abort all connections, and set the max number of
+ // connections to 0. Keep the list of peers, so we can quickly
+ // resume later.
+ d->setState(Paused);
+ foreach (PeerWireClient *client, d->connections)
+ client->abort();
+ d->connections.clear();
+ TorrentServer::instance()->removeClient(this);
+ } else {
+ // Restore the max number of connections, and start the peer
+ // connector. We should also quickly start receiving incoming
+ // connections.
+ d->setState(d->completedPieces.count(true) == d->fileManager.pieceCount()
+ ? Seeding : Searching);
+ connectToPeers();
+ TorrentServer::instance()->addClient(this);
+ }
+}
+
+void TorrentClient::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == d->uploadScheduleTimer) {
+ // Update the state of who's choked and who's not
+ scheduleUploads();
+ return;
+ }
+
+ if (event->timerId() != d->transferRateTimer) {
+ QObject::timerEvent(event);
+ return;
+ }
+
+ // Calculate average upload/download rate
+ qint64 uploadBytesPerSecond = 0;
+ qint64 downloadBytesPerSecond = 0;
+ for (int i = 0; i < RateControlWindowLength; ++i) {
+ uploadBytesPerSecond += d->uploadRate[i];
+ downloadBytesPerSecond += d->downloadRate[i];
+ }
+ uploadBytesPerSecond /= qint64(RateControlWindowLength);
+ downloadBytesPerSecond /= qint64(RateControlWindowLength);
+ for (int i = RateControlWindowLength - 2; i >= 0; --i) {
+ d->uploadRate[i + 1] = d->uploadRate[i];
+ d->downloadRate[i + 1] = d->downloadRate[i];
+ }
+ d->uploadRate[0] = 0;
+ d->downloadRate[0] = 0;
+ emit uploadRateUpdated(int(uploadBytesPerSecond));
+ emit downloadRateUpdated(int(downloadBytesPerSecond));
+
+ // Stop the timer if there is no activity.
+ if (downloadBytesPerSecond == 0 && uploadBytesPerSecond == 0) {
+ killTimer(d->transferRateTimer);
+ d->transferRateTimer = 0;
+ }
+}
+
+void TorrentClient::sendToPeer(int readId, int pieceIndex, int begin, const QByteArray &data)
+{
+ // Send the requested block to the peer if the client connection
+ // still exists; otherwise do nothing. This slot is called by the
+ // file manager after it has read a block of data.
+ PeerWireClient *client = d->readIds.value(readId);
+ if (client) {
+ if ((client->peerWireState() & PeerWireClient::ChokingPeer) == 0)
+ client->sendBlock(pieceIndex, begin, data);
+ }
+ d->readIds.remove(readId);
+}
+
+void TorrentClient::fullVerificationDone()
+{
+ // Update our list of completed and incomplete pieces.
+ d->completedPieces = d->fileManager.completedPieces();
+ d->incompletePieces.resize(d->completedPieces.size());
+ d->pieceCount = d->completedPieces.size();
+ for (int i = 0; i < d->fileManager.pieceCount(); ++i) {
+ if (!d->completedPieces.testBit(i))
+ d->incompletePieces.setBit(i);
+ }
+
+ updateProgress();
+
+ // If the checksums show that what the dumped state thought was
+ // partial was in fact complete, then we trust the checksums.
+ QMap<int, TorrentPiece *>::Iterator it = d->pendingPieces.begin();
+ while (it != d->pendingPieces.end()) {
+ if (d->completedPieces.testBit(it.key()))
+ it = d->pendingPieces.erase(it);
+ else
+ ++it;
+ }
+
+ d->uploadScheduleTimer = startTimer(UploadScheduleInterval);
+
+ // Start the server
+ TorrentServer *server = TorrentServer::instance();
+ if (!server->isListening()) {
+ // Set up the peer wire server
+ for (int i = ServerMinPort; i <= ServerMaxPort; ++i) {
+ if (server->listen(QHostAddress::Any, i))
+ break;
+ }
+ if (!server->isListening()) {
+ d->setError(ServerError);
+ return;
+ }
+ }
+
+ d->setState(d->completedPieces.count(true) == d->pieceCount ? Seeding : Searching);
+
+ // Start the tracker client
+ d->trackerClient.start(d->metaInfo);
+}
+
+void TorrentClient::pieceVerified(int pieceIndex, bool ok)
+{
+ TorrentPiece *piece = d->pendingPieces.value(pieceIndex);
+
+ // Remove this piece from all payloads
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.begin();
+ while (it != d->payloads.end()) {
+ if (it.value()->index == pieceIndex)
+ it = d->payloads.erase(it);
+ else
+ ++it;
+ }
+
+ if (!ok) {
+ // If a piece did not pass the SHA1 check, we'll simply clear
+ // its state, and the scheduler will re-request it
+ piece->inProgress = false;
+ piece->completedBlocks.fill(false);
+ piece->requestedBlocks.fill(false);
+ d->callScheduler();
+ return;
+ }
+
+ // Update the peer list so we know who's still interesting.
+ foreach (TorrentPeer *peer, d->peers) {
+ if (!peer->interesting)
+ continue;
+ bool interesting = false;
+ for (int i = 0; i < d->pieceCount; ++i) {
+ if (peer->pieces.testBit(i) && d->incompletePieces.testBit(i)) {
+ interesting = true;
+ break;
+ }
+ }
+ peer->interesting = interesting;
+ }
+
+ // Delete the piece and update our structures.
+ delete piece;
+ d->pendingPieces.remove(pieceIndex);
+ d->completedPieces.setBit(pieceIndex);
+ d->incompletePieces.clearBit(pieceIndex);
+
+ // Notify connected peers.
+ foreach (PeerWireClient *client, d->connections) {
+ if (client->state() == QAbstractSocket::ConnectedState
+ && !client->availablePieces().testBit(pieceIndex)) {
+ client->sendPieceNotification(pieceIndex);
+ }
+ }
+
+ // Notify the tracker if we've entered Seeding status; otherwise
+ // call the scheduler.
+ int completed = d->completedPieces.count(true);
+ if (completed == d->pieceCount) {
+ if (d->state != Seeding) {
+ d->setState(Seeding);
+ d->trackerClient.startSeeding();
+ }
+ } else {
+ if (completed == 1)
+ d->setState(Downloading);
+ else if (d->incompletePieces.count(true) < 5 && d->pendingPieces.size() > d->incompletePieces.count(true))
+ d->setState(Endgame);
+ d->callScheduler();
+ }
+
+ updateProgress();
+}
+
+void TorrentClient::handleFileError()
+{
+ if (d->state == Paused)
+ return;
+ setPaused(true);
+ emit error(FileError);
+}
+
+void TorrentClient::connectToPeers()
+{
+ d->connectingToClients = false;
+
+ if (d->state == Stopping || d->state == Idle || d->state == Paused)
+ return;
+
+ if (d->state == Searching)
+ d->setState(Connecting);
+
+ // Find the list of peers we are not currently connected to, where
+ // the more interesting peers are listed more than once.
+ QList<TorrentPeer *> weighedPeers = weighedFreePeers();
+
+ // Start as many connections as we can
+ while (!weighedPeers.isEmpty() && ConnectionManager::instance()->canAddConnection()
+ && (qrand() % (ConnectionManager::instance()->maxConnections() / 2))) {
+ PeerWireClient *client = new PeerWireClient(ConnectionManager::instance()->clientId(), this);
+ RateController::instance()->addSocket(client);
+ ConnectionManager::instance()->addConnection(client);
+
+ initializeConnection(client);
+ d->connections << client;
+
+ // Pick a random peer from the list of weighed peers.
+ TorrentPeer *peer = weighedPeers.takeAt(qrand() % weighedPeers.size());
+ weighedPeers.removeAll(peer);
+ peer->connectStart = QDateTime::currentDateTime().toTime_t();
+ peer->lastVisited = peer->connectStart;
+
+ // Connect to the peer.
+ client->setPeer(peer);
+ client->connectToHost(peer->address, peer->port);
+ }
+}
+
+QList<TorrentPeer *> TorrentClient::weighedFreePeers() const
+{
+ QList<TorrentPeer *> weighedPeers;
+
+ // Generate a list of peers that we want to connect to.
+ uint now = QDateTime::currentDateTime().toTime_t();
+ QList<TorrentPeer *> freePeers;
+ QMap<QString, int> connectionsPerPeer;
+ foreach (TorrentPeer *peer, d->peers) {
+ bool busy = false;
+ foreach (PeerWireClient *client, d->connections) {
+ if (client->state() == PeerWireClient::ConnectedState
+ && client->peerAddress() == peer->address
+ && client->peerPort() == peer->port) {
+ if (++connectionsPerPeer[peer->address.toString()] >= MaxConnectionPerPeer) {
+ busy = true;
+ break;
+ }
+ }
+ }
+ if (!busy && (now - peer->lastVisited) > uint(MinimumTimeBeforeRevisit))
+ freePeers << peer;
+ }
+
+ // Nothing to connect to
+ if (freePeers.isEmpty())
+ return weighedPeers;
+
+ // Assign points based on connection speed and pieces available.
+ QList<QPair<int, TorrentPeer *> > points;
+ foreach (TorrentPeer *peer, freePeers) {
+ int tmp = 0;
+ if (peer->interesting) {
+ tmp += peer->numCompletedPieces;
+ if (d->state == Seeding)
+ tmp = d->pieceCount - tmp;
+ if (!peer->connectStart) // An unknown peer is as interesting as a seed
+ tmp += d->pieceCount;
+
+ // 1/5 of the total score for each second below 5 it takes to
+ // connect.
+ if (peer->connectTime < 5)
+ tmp += (d->pieceCount / 10) * (5 - peer->connectTime);
+ }
+ points << QPair<int, TorrentPeer *>(tmp, peer);
+ }
+ qSort(points);
+
+ // Minimize the list so the point difference is never more than 1.
+ typedef QPair<int,TorrentPeer*> PointPair;
+ QMultiMap<int, TorrentPeer *> pointMap;
+ int lowestScore = 0;
+ int lastIndex = 0;
+ foreach (PointPair point, points) {
+ if (point.first > lowestScore) {
+ lowestScore = point.first;
+ ++lastIndex;
+ }
+ pointMap.insert(lastIndex, point.second);
+ }
+
+ // Now make up a list of peers where the ones with more points are
+ // listed many times.
+ QMultiMap<int, TorrentPeer *>::ConstIterator it = pointMap.constBegin();
+ while (it != pointMap.constEnd()) {
+ for (int i = 0; i < it.key() + 1; ++i)
+ weighedPeers << it.value();
+ ++it;
+ }
+
+ return weighedPeers;
+}
+
+void TorrentClient::setupIncomingConnection(PeerWireClient *client)
+{
+ // Connect signals
+ initializeConnection(client);
+
+ // Initialize this client
+ RateController::instance()->addSocket(client);
+ d->connections << client;
+
+ client->initialize(d->infoHash, d->pieceCount);
+ client->sendPieceList(d->completedPieces);
+
+ emit peerInfoUpdated();
+
+ if (d->state == Searching || d->state == Connecting) {
+ int completed = d->completedPieces.count(true);
+ if (completed == 0)
+ d->setState(WarmingUp);
+ else if (d->incompletePieces.count(true) < 5 && d->pendingPieces.size() > d->incompletePieces.count(true))
+ d->setState(Endgame);
+ }
+
+ if (d->connections.isEmpty())
+ scheduleUploads();
+}
+
+void TorrentClient::setupOutgoingConnection()
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+
+ // Update connection statistics.
+ foreach (TorrentPeer *peer, d->peers) {
+ if (peer->port == client->peerPort() && peer->address == client->peerAddress()) {
+ peer->connectTime = peer->lastVisited - peer->connectStart;
+ break;
+ }
+ }
+
+ // Send handshake and piece list
+ client->initialize(d->infoHash, d->pieceCount);
+ client->sendPieceList(d->completedPieces);
+
+ emit peerInfoUpdated();
+
+ if (d->state == Searching || d->state == Connecting) {
+ int completed = d->completedPieces.count(true);
+ if (completed == 0)
+ d->setState(WarmingUp);
+ else if (d->incompletePieces.count(true) < 5 && d->pendingPieces.size() > d->incompletePieces.count(true))
+ d->setState(Endgame);
+ }
+}
+
+void TorrentClient::initializeConnection(PeerWireClient *client)
+{
+ connect(client, SIGNAL(connected()),
+ this, SLOT(setupOutgoingConnection()));
+ connect(client, SIGNAL(disconnected()),
+ this, SLOT(removeClient()));
+ connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(removeClient()));
+ connect(client, SIGNAL(piecesAvailable(QBitArray)),
+ this, SLOT(peerPiecesAvailable(QBitArray)));
+ connect(client, SIGNAL(blockRequested(int,int,int)),
+ this, SLOT(peerRequestsBlock(int,int,int)));
+ connect(client, SIGNAL(blockReceived(int,int,QByteArray)),
+ this, SLOT(blockReceived(int,int,QByteArray)));
+ connect(client, SIGNAL(choked()),
+ this, SLOT(peerChoked()));
+ connect(client, SIGNAL(unchoked()),
+ this, SLOT(peerUnchoked()));
+ connect(client, SIGNAL(bytesWritten(qint64)),
+ this, SLOT(peerWireBytesWritten(qint64)));
+ connect(client, SIGNAL(bytesReceived(qint64)),
+ this, SLOT(peerWireBytesReceived(qint64)));
+}
+
+void TorrentClient::removeClient()
+{
+ PeerWireClient *client = static_cast<PeerWireClient *>(sender());
+
+ // Remove the host from our list of known peers if the connection
+ // failed.
+ if (client->peer() && client->error() == QAbstractSocket::ConnectionRefusedError)
+ d->peers.removeAll(client->peer());
+
+ // Remove the client from RateController and all structures.
+ RateController::instance()->removeSocket(client);
+ d->connections.removeAll(client);
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
+ while (it != d->payloads.end() && it.key() == client) {
+ TorrentPiece *piece = it.value();
+ piece->inProgress = false;
+ piece->requestedBlocks.fill(false);
+ it = d->payloads.erase(it);
+ }
+
+ // Remove pending read requests.
+ QMapIterator<int, PeerWireClient *> it2(d->readIds);
+ while (it2.findNext(client))
+ d->readIds.remove(it2.key());
+
+ // Delete the client later.
+ disconnect(client, SIGNAL(disconnected()), this, SLOT(removeClient()));
+ client->deleteLater();
+ ConnectionManager::instance()->removeConnection(client);
+
+ emit peerInfoUpdated();
+ d->callPeerConnector();
+}
+
+void TorrentClient::peerPiecesAvailable(const QBitArray &pieces)
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+
+ // Find the peer in our list of announced peers. If it's there,
+ // then we can use the piece list into to gather statistics that
+ // help us decide what peers to connect to.
+ TorrentPeer *peer = 0;
+ QList<TorrentPeer *>::Iterator it = d->peers.begin();
+ while (it != d->peers.end()) {
+ if ((*it)->address == client->peerAddress() && (*it)->port == client->peerPort()) {
+ peer = *it;
+ break;
+ }
+ ++it;
+ }
+
+ // If the peer is a seed, and we are in seeding mode, then the
+ // peer is uninteresting.
+ if (pieces.count(true) == d->pieceCount) {
+ if (peer)
+ peer->seed = true;
+ emit peerInfoUpdated();
+ if (d->state == Seeding) {
+ client->abort();
+ return;
+ } else {
+ if (peer)
+ peer->interesting = true;
+ if ((client->peerWireState() & PeerWireClient::InterestedInPeer) == 0)
+ client->sendInterested();
+ d->callScheduler();
+ return;
+ }
+ }
+
+ // Update our list of available pieces.
+ if (peer) {
+ peer->pieces = pieces;
+ peer->numCompletedPieces = pieces.count(true);
+ }
+
+ // Check for interesting pieces, and tell the peer whether we are
+ // interested or not.
+ bool interested = false;
+ int piecesSize = pieces.size();
+ for (int pieceIndex = 0; pieceIndex < piecesSize; ++pieceIndex) {
+ if (!pieces.testBit(pieceIndex))
+ continue;
+ if (!d->completedPieces.testBit(pieceIndex)) {
+ interested = true;
+ if ((client->peerWireState() & PeerWireClient::InterestedInPeer) == 0) {
+ if (peer)
+ peer->interesting = true;
+ client->sendInterested();
+ }
+
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
+ int inProgress = 0;
+ while (it != d->payloads.end() && it.key() == client) {
+ if (it.value()->inProgress)
+ inProgress += it.value()->requestedBlocks.count(true);
+ ++it;
+ }
+ if (!inProgress)
+ d->callScheduler();
+ break;
+ }
+ }
+ if (!interested && (client->peerWireState() & PeerWireClient::InterestedInPeer)) {
+ if (peer)
+ peer->interesting = false;
+ client->sendNotInterested();
+ }
+}
+
+void TorrentClient::peerRequestsBlock(int pieceIndex, int begin, int length)
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+
+ // Silently ignore requests from choked peers
+ if (client->peerWireState() & PeerWireClient::ChokingPeer)
+ return;
+
+ // Silently ignore requests for pieces we don't have.
+ if (!d->completedPieces.testBit(pieceIndex))
+ return;
+
+ // Request the block from the file manager
+ d->readIds.insert(d->fileManager.read(pieceIndex, begin, length),
+ qobject_cast<PeerWireClient *>(sender()));
+}
+
+void TorrentClient::blockReceived(int pieceIndex, int begin, const QByteArray &data)
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+ if (data.size() == 0) {
+ client->abort();
+ return;
+ }
+
+ // Ignore it if we already have this block.
+ int blockBit = begin / BlockSize;
+ TorrentPiece *piece = d->pendingPieces.value(pieceIndex);
+ if (!piece || piece->completedBlocks.testBit(blockBit)) {
+ // Discard blocks that we already have, and fill up the pipeline.
+ requestMore(client);
+ return;
+ }
+
+ // If we are in warmup or endgame mode, cancel all duplicate
+ // requests for this block.
+ if (d->state == WarmingUp || d->state == Endgame) {
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.begin();
+ while (it != d->payloads.end()) {
+ PeerWireClient *otherClient = it.key();
+ if (otherClient != client && it.value()->index == pieceIndex) {
+ if (otherClient->incomingBlocks().contains(TorrentBlock(pieceIndex, begin, data.size())))
+ it.key()->cancelRequest(pieceIndex, begin, data.size());
+ }
+ ++it;
+ }
+ }
+
+ if (d->state != Downloading && d->state != Endgame && d->completedPieces.count(true) > 0)
+ d->setState(Downloading);
+
+ // Store this block
+ d->fileManager.write(pieceIndex, begin, data);
+ piece->completedBlocks.setBit(blockBit);
+ piece->requestedBlocks.clearBit(blockBit);
+
+ if (blocksLeftForPiece(piece) == 0) {
+ // Ask the file manager to verify the newly downloaded piece
+ d->fileManager.verifyPiece(piece->index);
+
+ // Remove this piece from all payloads
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.begin();
+ while (it != d->payloads.end()) {
+ if (!it.value() || it.value()->index == piece->index)
+ it = d->payloads.erase(it);
+ else
+ ++it;
+ }
+ }
+
+ // Fill up the pipeline.
+ requestMore(client);
+}
+
+void TorrentClient::peerWireBytesWritten(qint64 size)
+{
+ if (!d->transferRateTimer)
+ d->transferRateTimer = startTimer(RateControlTimerDelay);
+
+ d->uploadRate[0] += size;
+ d->uploadedBytes += size;
+ emit dataSent(size);
+}
+
+void TorrentClient::peerWireBytesReceived(qint64 size)
+{
+ if (!d->transferRateTimer)
+ d->transferRateTimer = startTimer(RateControlTimerDelay);
+
+ d->downloadRate[0] += size;
+ d->downloadedBytes += size;
+ emit dataSent(size);
+}
+
+int TorrentClient::blocksLeftForPiece(const TorrentPiece *piece) const
+{
+ int blocksLeft = 0;
+ int completedBlocksSize = piece->completedBlocks.size();
+ for (int i = 0; i < completedBlocksSize; ++i) {
+ if (!piece->completedBlocks.testBit(i))
+ ++blocksLeft;
+ }
+ return blocksLeft;
+}
+
+void TorrentClient::scheduleUploads()
+{
+ // Generate a list of clients sorted by their transfer
+ // speeds. When leeching, we sort by download speed, and when
+ // seeding, we sort by upload speed. Seeds are left out; there's
+ // no use in unchoking them.
+ QList<PeerWireClient *> allClients = d->connections;
+ QMultiMap<int, PeerWireClient *> transferSpeeds;
+ foreach (PeerWireClient *client, allClients) {
+ if (client->state() == QAbstractSocket::ConnectedState
+ && client->availablePieces().count(true) != d->pieceCount) {
+ if (d->state == Seeding) {
+ transferSpeeds.insert(client->uploadSpeed(), client);
+ } else {
+ transferSpeeds.insert(client->downloadSpeed(), client);
+ }
+ }
+ }
+
+ // Unchoke the top 'MaxUploads' downloaders (peers that we are
+ // uploading to) and choke all others.
+ int maxUploaders = MaxUploads;
+ QMapIterator<int, PeerWireClient *> it(transferSpeeds);
+ it.toBack();
+ while (it.hasPrevious()) {
+ PeerWireClient *client = it.previous().value();
+ bool interested = (client->peerWireState() & PeerWireClient::PeerIsInterested);
+
+ if (maxUploaders) {
+ allClients.removeAll(client);
+ if (client->peerWireState() & PeerWireClient::ChokingPeer)
+ client->unchokePeer();
+ --maxUploaders;
+ continue;
+ }
+
+ if ((client->peerWireState() & PeerWireClient::ChokingPeer) == 0) {
+ if ((qrand() % 10) == 0)
+ client->abort();
+ else
+ client->chokePeer();
+ allClients.removeAll(client);
+ }
+ if (!interested)
+ allClients.removeAll(client);
+ }
+
+ // Only interested peers are left in allClients. Unchoke one
+ // random peer to allow it to compete for a position among the
+ // downloaders. (This is known as an "optimistic unchoke".)
+ if (!allClients.isEmpty()) {
+ PeerWireClient *client = allClients[qrand() % allClients.size()];
+ if (client->peerWireState() & PeerWireClient::ChokingPeer)
+ client->unchokePeer();
+ }
+}
+
+void TorrentClient::scheduleDownloads()
+{
+ d->schedulerCalled = false;
+
+ if (d->state == Stopping || d->state == Paused || d->state == Idle)
+ return;
+
+ // Check what each client is doing, and assign payloads to those
+ // who are either idle or done.
+ foreach (PeerWireClient *client, d->connections)
+ schedulePieceForClient(client);
+}
+
+void TorrentClient::schedulePieceForClient(PeerWireClient *client)
+{
+ // Only schedule connected clients.
+ if (client->state() != QTcpSocket::ConnectedState)
+ return;
+
+ // The peer has choked us; try again later.
+ if (client->peerWireState() & PeerWireClient::ChokedByPeer)
+ return;
+
+ // Make a list of all the client's pending pieces, and count how
+ // many blocks have been requested.
+ QList<int> currentPieces;
+ bool somePiecesAreNotInProgress = false;
+ TorrentPiece *lastPendingPiece = 0;
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
+ while (it != d->payloads.end() && it.key() == client) {
+ lastPendingPiece = it.value();
+ if (lastPendingPiece->inProgress) {
+ currentPieces << lastPendingPiece->index;
+ } else {
+ somePiecesAreNotInProgress = true;
+ }
+ ++it;
+ }
+
+ // Skip clients that already have too many blocks in progress.
+ if (client->incomingBlocks().size() >= ((d->state == Endgame || d->state == WarmingUp)
+ ? MaxBlocksInMultiMode : MaxBlocksInProgress))
+ return;
+
+ // If all pieces are in progress, but we haven't filled up our
+ // block requesting quota, then we need to schedule another piece.
+ if (!somePiecesAreNotInProgress || client->incomingBlocks().size() > 0)
+ lastPendingPiece = 0;
+ TorrentPiece *piece = lastPendingPiece;
+
+ // In warmup state, all clients request blocks from the same pieces.
+ if (d->state == WarmingUp && d->pendingPieces.size() >= 4) {
+ piece = d->payloads.value(client);
+ if (!piece) {
+ QList<TorrentPiece *> values = d->pendingPieces.values();
+ piece = values.value(qrand() % values.size());
+ piece->inProgress = true;
+ d->payloads.insert(client, piece);
+ }
+ if (piece->completedBlocks.count(false) == client->incomingBlocks().size())
+ return;
+ }
+
+ // If no pieces are currently in progress, schedule a new one.
+ if (!piece) {
+ // Build up a list of what pieces that we have not completed
+ // are available to this client.
+ QBitArray incompletePiecesAvailableToClient = d->incompletePieces;
+
+ // Remove all pieces that are marked as being in progress
+ // already (i.e., pieces that this or other clients are
+ // already waiting for). A special rule applies to warmup and
+ // endgame mode; there, we allow several clients to request
+ // the same piece. In endgame mode, this only applies to
+ // clients that are currently uploading (more than 1.0KB/s).
+ if ((d->state == Endgame && client->uploadSpeed() < 1024) || d->state != WarmingUp) {
+ QMap<int, TorrentPiece *>::ConstIterator it = d->pendingPieces.constBegin();
+ while (it != d->pendingPieces.constEnd()) {
+ if (it.value()->inProgress)
+ incompletePiecesAvailableToClient.clearBit(it.key());
+ ++it;
+ }
+ }
+
+ // Remove all pieces that the client cannot download.
+ incompletePiecesAvailableToClient &= client->availablePieces();
+
+ // Remove all pieces that this client has already requested.
+ foreach (int i, currentPieces)
+ incompletePiecesAvailableToClient.clearBit(i);
+
+ // Only continue if more pieces can be scheduled. If no pieces
+ // are available and no blocks are in progress, just leave
+ // the connection idle; it might become interesting later.
+ if (incompletePiecesAvailableToClient.count(true) == 0)
+ return;
+
+ // Check if any of the partially completed pieces can be
+ // recovered, and if so, pick a random one of them.
+ QList<TorrentPiece *> partialPieces;
+ QMap<int, TorrentPiece *>::ConstIterator it = d->pendingPieces.constBegin();
+ while (it != d->pendingPieces.constEnd()) {
+ TorrentPiece *tmp = it.value();
+ if (incompletePiecesAvailableToClient.testBit(it.key())) {
+ if (!tmp->inProgress || d->state == WarmingUp || d->state == Endgame) {
+ partialPieces << tmp;
+ break;
+ }
+ }
+ ++it;
+ }
+ if (!partialPieces.isEmpty())
+ piece = partialPieces.value(qrand() % partialPieces.size());
+
+ if (!piece) {
+ // Pick a random piece 3 out of 4 times; otherwise, pick either
+ // one of the most common or the least common pieces available,
+ // depending on the state we're in.
+ int pieceIndex = 0;
+ if (d->state == WarmingUp || (qrand() & 4) == 0) {
+ int *occurrences = new int[d->pieceCount];
+ memset(occurrences, 0, d->pieceCount * sizeof(int));
+
+ // Count how many of each piece are available.
+ foreach (PeerWireClient *peer, d->connections) {
+ QBitArray peerPieces = peer->availablePieces();
+ int peerPiecesSize = peerPieces.size();
+ for (int i = 0; i < peerPiecesSize; ++i) {
+ if (peerPieces.testBit(i))
+ ++occurrences[i];
+ }
+ }
+
+ // Find the rarest or most common pieces.
+ int numOccurrences = d->state == WarmingUp ? 0 : 99999;
+ QList<int> piecesReadyForDownload;
+ for (int i = 0; i < d->pieceCount; ++i) {
+ if (d->state == WarmingUp) {
+ // Add common pieces
+ if (occurrences[i] >= numOccurrences
+ && incompletePiecesAvailableToClient.testBit(i)) {
+ if (occurrences[i] > numOccurrences)
+ piecesReadyForDownload.clear();
+ piecesReadyForDownload.append(i);
+ numOccurrences = occurrences[i];
+ }
+ } else {
+ // Add rare pieces
+ if (occurrences[i] <= numOccurrences
+ && incompletePiecesAvailableToClient.testBit(i)) {
+ if (occurrences[i] < numOccurrences)
+ piecesReadyForDownload.clear();
+ piecesReadyForDownload.append(i);
+ numOccurrences = occurrences[i];
+ }
+ }
+ }
+
+ // Select one piece randomly
+ pieceIndex = piecesReadyForDownload.at(qrand() % piecesReadyForDownload.size());
+ delete [] occurrences;
+ } else {
+ // Make up a list of available piece indices, and pick
+ // a random one.
+ QList<int> values;
+ int incompletePiecesAvailableToClientSize = incompletePiecesAvailableToClient.size();
+ for (int i = 0; i < incompletePiecesAvailableToClientSize; ++i) {
+ if (incompletePiecesAvailableToClient.testBit(i))
+ values << i;
+ }
+ pieceIndex = values.at(qrand() % values.size());
+ }
+
+ // Create a new TorrentPiece and fill in all initial
+ // properties.
+ piece = new TorrentPiece;
+ piece->index = pieceIndex;
+ piece->length = d->fileManager.pieceLengthAt(pieceIndex);
+ int numBlocks = piece->length / BlockSize;
+ if (piece->length % BlockSize)
+ ++numBlocks;
+ piece->completedBlocks.resize(numBlocks);
+ piece->requestedBlocks.resize(numBlocks);
+ d->pendingPieces.insert(pieceIndex, piece);
+ }
+
+ piece->inProgress = true;
+ d->payloads.insert(client, piece);
+ }
+
+ // Request more blocks from all pending pieces.
+ requestMore(client);
+}
+
+void TorrentClient::requestMore(PeerWireClient *client)
+{
+ // Make a list of all pieces this client is currently waiting for,
+ // and count the number of blocks in progress.
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
+ int numBlocksInProgress = client->incomingBlocks().size();
+ QList<TorrentPiece *> piecesInProgress;
+ while (it != d->payloads.end() && it.key() == client) {
+ TorrentPiece *piece = it.value();
+ if (piece->inProgress || (d->state == WarmingUp || d->state == Endgame))
+ piecesInProgress << piece;
+ ++it;
+ }
+
+ // If no pieces are in progress, call the scheduler.
+ if (piecesInProgress.isEmpty() && d->incompletePieces.count(true)) {
+ d->callScheduler();
+ return;
+ }
+
+ // If too many pieces are in progress, there's nothing to do.
+ int maxInProgress = ((d->state == Endgame || d->state == WarmingUp)
+ ? MaxBlocksInMultiMode : MaxBlocksInProgress);
+ if (numBlocksInProgress == maxInProgress)
+ return;
+
+ // Starting with the first piece that we're waiting for, request
+ // blocks until the quota is filled up.
+ foreach (TorrentPiece *piece, piecesInProgress) {
+ numBlocksInProgress += requestBlocks(client, piece, maxInProgress - numBlocksInProgress);
+ if (numBlocksInProgress == maxInProgress)
+ break;
+ }
+
+ // If we still didn't fill up the quota, we need to schedule more
+ // pieces.
+ if (numBlocksInProgress < maxInProgress && d->state != WarmingUp)
+ d->callScheduler();
+}
+
+int TorrentClient::requestBlocks(PeerWireClient *client, TorrentPiece *piece, int maxBlocks)
+{
+ // Generate the list of incomplete blocks for this piece.
+ QVector<int> bits;
+ int completedBlocksSize = piece->completedBlocks.size();
+ for (int i = 0; i < completedBlocksSize; ++i) {
+ if (!piece->completedBlocks.testBit(i) && !piece->requestedBlocks.testBit(i))
+ bits << i;
+ }
+
+ // Nothing more to request.
+ if (bits.size() == 0) {
+ if (d->state != WarmingUp && d->state != Endgame)
+ return 0;
+ bits.clear();
+ for (int i = 0; i < completedBlocksSize; ++i) {
+ if (!piece->completedBlocks.testBit(i))
+ bits << i;
+ }
+ }
+
+ if (d->state == WarmingUp || d->state == Endgame) {
+ // By randomizing the list of blocks to request, we
+ // significantly speed up the warmup and endgame modes, where
+ // the same blocks are requested from multiple peers. The
+ // speedup comes from an increased chance of receiving
+ // different blocks from the different peers.
+ for (int i = 0; i < bits.size(); ++i) {
+ int a = qrand() % bits.size();
+ int b = qrand() % bits.size();
+ int tmp = bits[a];
+ bits[a] = bits[b];
+ bits[b] = tmp;
+ }
+ }
+
+ // Request no more blocks than we've been asked to.
+ int blocksToRequest = qMin(maxBlocks, bits.size());
+
+ // Calculate the offset and size of each block, and send requests.
+ for (int i = 0; i < blocksToRequest; ++i) {
+ int blockSize = BlockSize;
+ if ((piece->length % BlockSize) && bits.at(i) == completedBlocksSize - 1)
+ blockSize = piece->length % BlockSize;
+ client->requestBlock(piece->index, bits.at(i) * BlockSize, blockSize);
+ piece->requestedBlocks.setBit(bits.at(i));
+ }
+
+ return blocksToRequest;
+}
+
+void TorrentClient::peerChoked()
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+ if (!client)
+ return;
+
+ // When the peer chokes us, we immediately forget about all blocks
+ // we've requested from it. We also remove the piece from out
+ // payload, making it available to other clients.
+ QMultiMap<PeerWireClient *, TorrentPiece *>::Iterator it = d->payloads.find(client);
+ while (it != d->payloads.end() && it.key() == client) {
+ it.value()->inProgress = false;
+ it.value()->requestedBlocks.fill(false);
+ it = d->payloads.erase(it);
+ }
+}
+
+void TorrentClient::peerUnchoked()
+{
+ PeerWireClient *client = qobject_cast<PeerWireClient *>(sender());
+ if (!client)
+ return;
+
+ // We got unchoked, which means we can request more blocks.
+ if (d->state != Seeding)
+ d->callScheduler();
+}
+
+void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList)
+{
+ // Add peers we don't already know of to our list of peers.
+ QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
+ foreach (TorrentPeer peer, peerList) {
+ if (addresses.contains(peer.address)
+ && peer.port == TorrentServer::instance()->serverPort()) {
+ // Skip our own server.
+ continue;
+ }
+
+ bool known = false;
+ foreach (TorrentPeer *knownPeer, d->peers) {
+ if (knownPeer->port == peer.port
+ && knownPeer->address == peer.address) {
+ known = true;
+ break;
+ }
+ }
+ if (!known) {
+ TorrentPeer *newPeer = new TorrentPeer;
+ *newPeer = peer;
+ newPeer->interesting = true;
+ newPeer->seed = false;
+ newPeer->lastVisited = 0;
+ newPeer->connectStart = 0;
+ newPeer->connectTime = 999999;
+ newPeer->pieces.resize(d->pieceCount);
+ newPeer->numCompletedPieces = 0;
+ d->peers << newPeer;
+ }
+ }
+
+ // If we've got more peers than we can connect to, we remove some
+ // of the peers that have no (or low) activity.
+ int maxPeers = ConnectionManager::instance()->maxConnections() * 3;
+ if (d->peers.size() > maxPeers) {
+ // Find what peers are currently connected & active
+ QSet<TorrentPeer *> activePeers;
+ foreach (TorrentPeer *peer, d->peers) {
+ foreach (PeerWireClient *client, d->connections) {
+ if (client->peer() == peer && (client->downloadSpeed() + client->uploadSpeed()) > 1024)
+ activePeers << peer;
+ }
+ }
+
+ // Remove inactive peers from the peer list until we're below
+ // the max connections count.
+ QList<int> toRemove;
+ for (int i = 0; i < d->peers.size() && (d->peers.size() - toRemove.size()) > maxPeers; ++i) {
+ if (!activePeers.contains(d->peers.at(i)))
+ toRemove << i;
+ }
+ QListIterator<int> toRemoveIterator(toRemove);
+ toRemoveIterator.toBack();
+ while (toRemoveIterator.hasPrevious())
+ d->peers.removeAt(toRemoveIterator.previous());
+
+ // If we still have too many peers, remove the oldest ones.
+ while (d->peers.size() > maxPeers)
+ d->peers.takeFirst();
+ }
+
+ if (d->state != Paused && d->state != Stopping && d->state != Idle) {
+ if (d->state == Searching || d->state == WarmingUp)
+ connectToPeers();
+ else
+ d->callPeerConnector();
+ }
+}
+
+void TorrentClient::trackerStopped()
+{
+ d->setState(Idle);
+ emit stopped();
+}
+
+void TorrentClient::updateProgress(int progress)
+{
+ if (progress == -1 && d->pieceCount > 0) {
+ int newProgress = (d->completedPieces.count(true) * 100) / d->pieceCount;
+ if (d->lastProgressValue != newProgress) {
+ d->lastProgressValue = newProgress;
+ emit progressUpdated(newProgress);
+ }
+ } else if (d->lastProgressValue != progress) {
+ d->lastProgressValue = progress;
+ emit progressUpdated(progress);
+ }
+}
diff --git a/examples/network/torrent/torrentclient.h b/examples/network/torrent/torrentclient.h
new file mode 100644
index 0000000000..7978e8e1f4
--- /dev/null
+++ b/examples/network/torrent/torrentclient.h
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TORRENTCLIENT_H
+#define TORRENTCLIENT_H
+
+#include <QBitArray>
+#include <QHostAddress>
+#include <QList>
+
+class MetaInfo;
+class PeerWireClient;
+class TorrentClientPrivate;
+class TorrentPeer;
+class TorrentPiece;
+QT_BEGIN_NAMESPACE
+class QTimerEvent;
+QT_END_NAMESPACE
+
+class TorrentPeer {
+public:
+ QHostAddress address;
+ quint16 port;
+ QString id;
+ bool interesting;
+ bool seed;
+ uint lastVisited;
+ uint connectStart;
+ uint connectTime;
+ QBitArray pieces;
+ int numCompletedPieces;
+
+ inline bool operator==(const TorrentPeer &other)
+ {
+ return port == other.port
+ && address == other.address
+ && id == other.id;
+ }
+};
+
+class TorrentClient : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum State {
+ Idle,
+ Paused,
+ Stopping,
+ Preparing,
+ Searching,
+ Connecting,
+ WarmingUp,
+ Downloading,
+ Endgame,
+ Seeding
+ };
+ enum Error {
+ UnknownError,
+ TorrentParseError,
+ InvalidTrackerError,
+ FileError,
+ ServerError
+ };
+
+ TorrentClient(QObject *parent = 0);
+ ~TorrentClient();
+
+ bool setTorrent(const QString &fileName);
+ bool setTorrent(const QByteArray &torrentData);
+ MetaInfo metaInfo() const;
+
+ void setMaxConnections(int connections);
+ int maxConnections() const;
+
+ void setDestinationFolder(const QString &directory);
+ QString destinationFolder() const;
+
+ void setDumpedState(const QByteArray &dumpedState);
+ QByteArray dumpedState() const;
+
+ // Progress and stats for download feedback.
+ qint64 progress() const;
+ void setDownloadedBytes(qint64 bytes);
+ qint64 downloadedBytes() const;
+ void setUploadedBytes(qint64 bytes);
+ qint64 uploadedBytes() const;
+ int connectedPeerCount() const;
+ int seedCount() const;
+
+ // Accessors for the tracker
+ QByteArray peerId() const;
+ QByteArray infoHash() const;
+ quint16 serverPort() const;
+
+ // State and error.
+ State state() const;
+ QString stateString() const;
+ Error error() const;
+ QString errorString() const;
+
+signals:
+ void stateChanged(TorrentClient::State state);
+ void error(TorrentClient::Error error);
+
+ void downloadCompleted();
+ void peerInfoUpdated();
+
+ void dataSent(int uploadedBytes);
+ void dataReceived(int downloadedBytes);
+ void progressUpdated(int percentProgress);
+ void downloadRateUpdated(int bytesPerSecond);
+ void uploadRateUpdated(int bytesPerSecond);
+
+ void stopped();
+
+public slots:
+ void start();
+ void stop();
+ void setPaused(bool paused);
+ void setupIncomingConnection(PeerWireClient *client);
+
+protected slots:
+ void timerEvent(QTimerEvent *event);
+
+private slots:
+ // File management
+ void sendToPeer(int readId, int pieceIndex, int begin, const QByteArray &data);
+ void fullVerificationDone();
+ void pieceVerified(int pieceIndex, bool ok);
+ void handleFileError();
+
+ // Connection handling
+ void connectToPeers();
+ QList<TorrentPeer *> weighedFreePeers() const;
+ void setupOutgoingConnection();
+ void initializeConnection(PeerWireClient *client);
+ void removeClient();
+ void peerPiecesAvailable(const QBitArray &pieces);
+ void peerRequestsBlock(int pieceIndex, int begin, int length);
+ void blockReceived(int pieceIndex, int begin, const QByteArray &data);
+ void peerWireBytesWritten(qint64 bytes);
+ void peerWireBytesReceived(qint64 bytes);
+ int blocksLeftForPiece(const TorrentPiece *piece) const;
+
+ // Scheduling
+ void scheduleUploads();
+ void scheduleDownloads();
+ void schedulePieceForClient(PeerWireClient *client);
+ void requestMore(PeerWireClient *client);
+ int requestBlocks(PeerWireClient *client, TorrentPiece *piece, int maxBlocks);
+ void peerChoked();
+ void peerUnchoked();
+
+ // Tracker handling
+ void addToPeerList(const QList<TorrentPeer> &peerList);
+ void trackerStopped();
+
+ // Progress
+ void updateProgress(int progress = -1);
+
+private:
+ TorrentClientPrivate *d;
+ friend class TorrentClientPrivate;
+};
+
+#endif
diff --git a/examples/network/torrent/torrentserver.cpp b/examples/network/torrent/torrentserver.cpp
new file mode 100644
index 0000000000..7a9ff67972
--- /dev/null
+++ b/examples/network/torrent/torrentserver.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "connectionmanager.h"
+#include "peerwireclient.h"
+#include "ratecontroller.h"
+#include "torrentclient.h"
+#include "torrentserver.h"
+
+Q_GLOBAL_STATIC(TorrentServer, torrentServer)
+
+TorrentServer *TorrentServer::instance()
+{
+ return torrentServer();
+}
+
+void TorrentServer::addClient(TorrentClient *client)
+{
+ clients << client;
+}
+
+void TorrentServer::removeClient(TorrentClient *client)
+{
+ clients.removeAll(client);
+}
+
+void TorrentServer::incomingConnection(int socketDescriptor)
+{
+ PeerWireClient *client =
+ new PeerWireClient(ConnectionManager::instance()->clientId(), this);
+
+ if (client->setSocketDescriptor(socketDescriptor)) {
+ if (ConnectionManager::instance()->canAddConnection() && !clients.isEmpty()) {
+ connect(client, SIGNAL(infoHashReceived(QByteArray)),
+ this, SLOT(processInfoHash(QByteArray)));
+ connect(client, SIGNAL(error(QAbstractSocket::SocketError)),
+ this, SLOT(removeClient()));
+ RateController::instance()->addSocket(client);
+ ConnectionManager::instance()->addConnection(client);
+ return;
+ }
+ }
+ client->abort();
+ delete client;
+}
+
+void TorrentServer::removeClient()
+{
+ PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
+ RateController::instance()->removeSocket(peer);
+ ConnectionManager::instance()->removeConnection(peer);
+ peer->deleteLater();
+}
+
+void TorrentServer::processInfoHash(const QByteArray &infoHash)
+{
+ PeerWireClient *peer = qobject_cast<PeerWireClient *>(sender());
+ foreach (TorrentClient *client, clients) {
+ if (client->state() >= TorrentClient::Searching && client->infoHash() == infoHash) {
+ peer->disconnect(peer, 0, this, 0);
+ client->setupIncomingConnection(peer);
+ return;
+ }
+ }
+ removeClient();
+}
diff --git a/examples/network/torrent/torrentserver.h b/examples/network/torrent/torrentserver.h
new file mode 100644
index 0000000000..2622384cfd
--- /dev/null
+++ b/examples/network/torrent/torrentserver.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TORRENTSERVER_H
+#define TORRENTSERVER_H
+
+#include <QList>
+#include <QTcpServer>
+
+class TorrentClient;
+
+class TorrentServer : public QTcpServer
+{
+ Q_OBJECT
+
+public:
+ inline TorrentServer() {}
+ static TorrentServer *instance();
+
+ void addClient(TorrentClient *client);
+ void removeClient(TorrentClient *client);
+
+protected:
+ void incomingConnection(int socketDescriptor);
+
+private slots:
+ void removeClient();
+ void processInfoHash(const QByteArray &infoHash);
+
+private:
+ QList<TorrentClient *> clients;
+};
+
+#endif
diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp
new file mode 100644
index 0000000000..0b9a5815c9
--- /dev/null
+++ b/examples/network/torrent/trackerclient.cpp
@@ -0,0 +1,236 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "bencodeparser.h"
+#include "connectionmanager.h"
+#include "torrentclient.h"
+#include "torrentserver.h"
+#include "trackerclient.h"
+
+#include <QtCore>
+
+TrackerClient::TrackerClient(TorrentClient *downloader, QObject *parent)
+ : QObject(parent), torrentDownloader(downloader)
+{
+ length = 0;
+ requestInterval = 5 * 60;
+ requestIntervalTimer = -1;
+ firstTrackerRequest = true;
+ lastTrackerRequest = false;
+ firstSeeding = true;
+
+ connect(&http, SIGNAL(done(bool)), this, SLOT(httpRequestDone(bool)));
+}
+
+void TrackerClient::start(const MetaInfo &info)
+{
+ metaInfo = info;
+ QTimer::singleShot(0, this, SLOT(fetchPeerList()));
+
+ if (metaInfo.fileForm() == MetaInfo::SingleFileForm) {
+ length = metaInfo.singleFile().length;
+ } else {
+ QList<MetaInfoMultiFile> files = metaInfo.multiFiles();
+ for (int i = 0; i < files.size(); ++i)
+ length += files.at(i).length;
+ }
+}
+
+void TrackerClient::startSeeding()
+{
+ firstSeeding = true;
+ fetchPeerList();
+}
+
+void TrackerClient::stop()
+{
+ lastTrackerRequest = true;
+ http.abort();
+ fetchPeerList();
+}
+
+void TrackerClient::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == requestIntervalTimer) {
+ if (http.state() == QHttp::Unconnected)
+ fetchPeerList();
+ } else {
+ QObject::timerEvent(event);
+ }
+}
+
+void TrackerClient::fetchPeerList()
+{
+ // Prepare connection details
+ QString fullUrl = metaInfo.announceUrl();
+ QUrl url(fullUrl);
+ QString passkey = "?";
+ if (fullUrl.contains("?passkey")) {
+ passkey = metaInfo.announceUrl().mid(fullUrl.indexOf("?passkey"), -1);
+ passkey += '&';
+ }
+
+ // Percent encode the hash
+ QByteArray infoHash = torrentDownloader->infoHash();
+ QString encodedSum;
+ for (int i = 0; i < infoHash.size(); ++i) {
+ encodedSum += '%';
+ encodedSum += QString::number(infoHash[i], 16).right(2).rightJustified(2, '0');
+ }
+
+ bool seeding = (torrentDownloader->state() == TorrentClient::Seeding);
+ QByteArray query;
+ query += url.path().toLatin1();
+ query += passkey;
+ query += "info_hash=" + encodedSum;
+ query += "&peer_id=" + ConnectionManager::instance()->clientId();
+ query += "&port=" + QByteArray::number(TorrentServer::instance()->serverPort());
+ query += "&compact=1";
+ query += "&uploaded=" + QByteArray::number(torrentDownloader->uploadedBytes());
+
+ if (!firstSeeding) {
+ query += "&downloaded=0";
+ query += "&left=0";
+ } else {
+ query += "&downloaded=" + QByteArray::number(
+ torrentDownloader->downloadedBytes());
+ int left = qMax<int>(0, metaInfo.totalSize() - torrentDownloader->downloadedBytes());
+ query += "&left=" + QByteArray::number(seeding ? 0 : left);
+ }
+
+ if (seeding && firstSeeding) {
+ query += "&event=completed";
+ firstSeeding = false;
+ } else if (firstTrackerRequest) {
+ firstTrackerRequest = false;
+ query += "&event=started";
+ } else if(lastTrackerRequest) {
+ query += "&event=stopped";
+ }
+
+ if (!trackerId.isEmpty())
+ query += "&trackerid=" + trackerId;
+
+ http.setHost(url.host(), url.port() == -1 ? 80 : url.port());
+ if (!url.userName().isEmpty())
+ http.setUser(url.userName(), url.password());
+ http.get(query);
+}
+
+void TrackerClient::httpRequestDone(bool error)
+{
+ if (lastTrackerRequest) {
+ emit stopped();
+ return;
+ }
+
+ if (error) {
+ emit connectionError(http.error());
+ return;
+ }
+
+ QByteArray response = http.readAll();
+ http.abort();
+
+ BencodeParser parser;
+ if (!parser.parse(response)) {
+ qWarning("Error parsing bencode response from tracker: %s",
+ qPrintable(parser.errorString()));
+ http.abort();
+ return;
+ }
+
+ QMap<QByteArray, QVariant> dict = parser.dictionary();
+
+ if (dict.contains("failure reason")) {
+ // no other items are present
+ emit failure(QString::fromUtf8(dict.value("failure reason").toByteArray()));
+ return;
+ }
+
+ if (dict.contains("warning message")) {
+ // continue processing
+ emit warning(QString::fromUtf8(dict.value("warning message").toByteArray()));
+ }
+
+ if (dict.contains("tracker id")) {
+ // store it
+ trackerId = dict.value("tracker id").toByteArray();
+ }
+
+ if (dict.contains("interval")) {
+ // Mandatory item
+ if (requestIntervalTimer != -1)
+ killTimer(requestIntervalTimer);
+ requestIntervalTimer = startTimer(dict.value("interval").toInt() * 1000);
+ }
+
+ if (dict.contains("peers")) {
+ // store it
+ peers.clear();
+ QVariant peerEntry = dict.value("peers");
+ if (peerEntry.type() == QVariant::List) {
+ QList<QVariant> peerTmp = peerEntry.toList();
+ for (int i = 0; i < peerTmp.size(); ++i) {
+ TorrentPeer tmp;
+ QMap<QByteArray, QVariant> peer = qvariant_cast<QMap<QByteArray, QVariant> >(peerTmp.at(i));
+ tmp.id = QString::fromUtf8(peer.value("peer id").toByteArray());
+ tmp.address.setAddress(QString::fromUtf8(peer.value("ip").toByteArray()));
+ tmp.port = peer.value("port").toInt();
+ peers << tmp;
+ }
+ } else {
+ QByteArray peerTmp = peerEntry.toByteArray();
+ for (int i = 0; i < peerTmp.size(); i += 6) {
+ TorrentPeer tmp;
+ uchar *data = (uchar *)peerTmp.constData() + i;
+ tmp.port = (int(data[4]) << 8) + data[5];
+ uint ipAddress = 0;
+ ipAddress += uint(data[0]) << 24;
+ ipAddress += uint(data[1]) << 16;
+ ipAddress += uint(data[2]) << 8;
+ ipAddress += uint(data[3]);
+ tmp.address.setAddress(ipAddress);
+ peers << tmp;
+ }
+ }
+ emit peerListUpdated(peers);
+ }
+}
diff --git a/examples/network/torrent/trackerclient.h b/examples/network/torrent/trackerclient.h
new file mode 100644
index 0000000000..de63a8f87f
--- /dev/null
+++ b/examples/network/torrent/trackerclient.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TRACKERCLIENT_H
+#define TRACKERCLIENT_H
+
+#include <QByteArray>
+#include <QList>
+#include <QObject>
+#include <QHostAddress>
+#include <QHttp>
+
+#include "metainfo.h"
+#include "torrentclient.h"
+
+class TorrentClient;
+
+class TrackerClient : public QObject
+{
+ Q_OBJECT
+
+public:
+ TrackerClient(TorrentClient *downloader, QObject *parent = 0);
+
+ void start(const MetaInfo &info);
+ void stop();
+ void startSeeding();
+
+signals:
+ void connectionError(QHttp::Error error);
+
+ void failure(const QString &reason);
+ void warning(const QString &message);
+ void peerListUpdated(const QList<TorrentPeer> &peerList);
+
+ void uploadCountUpdated(qint64 newUploadCount);
+ void downloadCountUpdated(qint64 newDownloadCount);
+
+ void stopped();
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private slots:
+ void fetchPeerList();
+ void httpRequestDone(bool error);
+
+private:
+ TorrentClient *torrentDownloader;
+
+ int requestInterval;
+ int requestIntervalTimer;
+ QHttp http;
+ MetaInfo metaInfo;
+ QByteArray trackerId;
+ QList<TorrentPeer> peers;
+ qint64 uploadedBytes;
+ qint64 downloadedBytes;
+ qint64 length;
+
+ bool firstTrackerRequest;
+ bool lastTrackerRequest;
+ bool firstSeeding;
+};
+
+#endif
diff --git a/examples/opengl/2dpainting/2dpainting.pro b/examples/opengl/2dpainting/2dpainting.pro
new file mode 100644
index 0000000000..120d6e4986
--- /dev/null
+++ b/examples/opengl/2dpainting/2dpainting.pro
@@ -0,0 +1,19 @@
+QT += opengl
+
+HEADERS = glwidget.h \
+ helper.h \
+ widget.h \
+ window.h
+SOURCES = glwidget.cpp \
+ helper.cpp \
+ main.cpp \
+ widget.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/2dpainting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 2dpainting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/2dpainting
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/2dpainting/glwidget.cpp b/examples/opengl/2dpainting/glwidget.cpp
new file mode 100644
index 0000000000..8b28a6e6a3
--- /dev/null
+++ b/examples/opengl/2dpainting/glwidget.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "glwidget.h"
+#include "helper.h"
+
+//! [0]
+GLWidget::GLWidget(Helper *helper, QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
+{
+ elapsed = 0;
+ setFixedSize(200, 200);
+ setAutoFillBackground(false);
+}
+//! [0]
+
+//! [1]
+void GLWidget::animate()
+{
+ elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
+ repaint();
+}
+//! [1]
+
+//! [2]
+void GLWidget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter;
+ painter.begin(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ helper->paint(&painter, event, elapsed);
+ painter.end();
+}
+//! [2]
diff --git a/examples/opengl/2dpainting/glwidget.h b/examples/opengl/2dpainting/glwidget.h
new file mode 100644
index 0000000000..c012960f31
--- /dev/null
+++ b/examples/opengl/2dpainting/glwidget.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+//! [0]
+class Helper;
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+class QWidget;
+QT_END_NAMESPACE
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(Helper *helper, QWidget *parent);
+
+public slots:
+ void animate();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ Helper *helper;
+ int elapsed;
+};
+//! [0]
+
+#endif
diff --git a/examples/opengl/2dpainting/helper.cpp b/examples/opengl/2dpainting/helper.cpp
new file mode 100644
index 0000000000..662a4264a7
--- /dev/null
+++ b/examples/opengl/2dpainting/helper.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "helper.h"
+
+//! [0]
+Helper::Helper()
+{
+ QLinearGradient gradient(QPointF(50, -20), QPointF(80, 20));
+ gradient.setColorAt(0.0, Qt::white);
+ gradient.setColorAt(1.0, QColor(0xa6, 0xce, 0x39));
+
+ background = QBrush(QColor(64, 32, 64));
+ circleBrush = QBrush(gradient);
+ circlePen = QPen(Qt::black);
+ circlePen.setWidth(1);
+ textPen = QPen(Qt::white);
+ textFont.setPixelSize(50);
+}
+//! [0]
+
+//! [1]
+void Helper::paint(QPainter *painter, QPaintEvent *event, int elapsed)
+{
+ painter->fillRect(event->rect(), background);
+ painter->translate(100, 100);
+//! [1]
+
+//! [2]
+ painter->save();
+ painter->setBrush(circleBrush);
+ painter->setPen(circlePen);
+ painter->rotate(elapsed * 0.030);
+
+ qreal r = elapsed/1000.0;
+ int n = 30;
+ for (int i = 0; i < n; ++i) {
+ painter->rotate(30);
+ qreal radius = 0 + 120.0*((i+r)/n);
+ qreal circleRadius = 1 + ((i+r)/n)*20;
+ painter->drawEllipse(QRectF(radius, -circleRadius,
+ circleRadius*2, circleRadius*2));
+ }
+ painter->restore();
+//! [2]
+
+//! [3]
+ painter->setPen(textPen);
+ painter->setFont(textFont);
+ painter->drawText(QRect(-50, -50, 100, 100), Qt::AlignCenter, "Qt");
+}
+//! [3]
diff --git a/examples/opengl/2dpainting/helper.h b/examples/opengl/2dpainting/helper.h
new file mode 100644
index 0000000000..380399fa50
--- /dev/null
+++ b/examples/opengl/2dpainting/helper.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HELPER_H
+#define HELPER_H
+
+#include <QBrush>
+#include <QFont>
+#include <QPen>
+
+QT_BEGIN_NAMESPACE
+class QPainter;
+class QPaintEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class Helper
+{
+public:
+ Helper();
+
+public:
+ void paint(QPainter *painter, QPaintEvent *event, int elapsed);
+
+private:
+ QBrush background;
+ QBrush circleBrush;
+ QFont textFont;
+ QPen circlePen;
+ QPen textPen;
+};
+//! [0]
+
+#endif
diff --git a/examples/opengl/2dpainting/main.cpp b/examples/opengl/2dpainting/main.cpp
new file mode 100644
index 0000000000..aedfd9f8d3
--- /dev/null
+++ b/examples/opengl/2dpainting/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/opengl/2dpainting/widget.cpp b/examples/opengl/2dpainting/widget.cpp
new file mode 100644
index 0000000000..16398147c7
--- /dev/null
+++ b/examples/opengl/2dpainting/widget.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "widget.h"
+#include "helper.h"
+
+
+//! [0]
+Widget::Widget(Helper *helper, QWidget *parent)
+ : QWidget(parent), helper(helper)
+{
+ elapsed = 0;
+ setFixedSize(200, 200);
+}
+//! [0]
+
+//! [1]
+void Widget::animate()
+{
+ elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
+ repaint();
+}
+//! [1]
+
+//! [2]
+void Widget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter;
+ painter.begin(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ helper->paint(&painter, event, elapsed);
+ painter.end();
+}
+//! [2]
diff --git a/examples/opengl/2dpainting/widget.h b/examples/opengl/2dpainting/widget.h
new file mode 100644
index 0000000000..7a67aaf1bf
--- /dev/null
+++ b/examples/opengl/2dpainting/widget.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WIDGET_H
+#define WIDGET_H
+
+#include <QWidget>
+
+//! [0]
+class Helper;
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+QT_END_NAMESPACE
+
+class Widget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Widget(Helper *helper, QWidget *parent);
+
+public slots:
+ void animate();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ Helper *helper;
+ int elapsed;
+};
+//! [0]
+
+#endif
diff --git a/examples/opengl/2dpainting/window.cpp b/examples/opengl/2dpainting/window.cpp
new file mode 100644
index 0000000000..d2c8ef706c
--- /dev/null
+++ b/examples/opengl/2dpainting/window.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "glwidget.h"
+#include "widget.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+ : QWidget()
+{
+ Widget *native = new Widget(&helper, this);
+ GLWidget *openGL = new GLWidget(&helper, this);
+ QLabel *nativeLabel = new QLabel(tr("Native"));
+ nativeLabel->setAlignment(Qt::AlignHCenter);
+ QLabel *openGLLabel = new QLabel(tr("OpenGL"));
+ openGLLabel->setAlignment(Qt::AlignHCenter);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(native, 0, 0);
+ layout->addWidget(openGL, 0, 1);
+ layout->addWidget(nativeLabel, 1, 0);
+ layout->addWidget(openGLLabel, 1, 1);
+ setLayout(layout);
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), native, SLOT(animate()));
+ connect(timer, SIGNAL(timeout()), openGL, SLOT(animate()));
+ timer->start(50);
+
+ setWindowTitle(tr("2D Painting on Native and OpenGL Widgets"));
+}
+//! [0]
diff --git a/examples/opengl/2dpainting/window.h b/examples/opengl/2dpainting/window.h
new file mode 100644
index 0000000000..0f983d20ac
--- /dev/null
+++ b/examples/opengl/2dpainting/window.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+#include "helper.h"
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ Helper helper;
+};
+//! [0]
+
+#endif
diff --git a/examples/opengl/README b/examples/opengl/README
new file mode 100644
index 0000000000..69bd134246
--- /dev/null
+++ b/examples/opengl/README
@@ -0,0 +1,41 @@
+Qt provides support for integration with OpenGL implementations on all
+platforms, giving developers the opportunity to display hardware accelerated
+3D graphics alongside a more conventional user interface.
+
+These examples demonstrate the basic techniques used to take advantage of
+OpenGL in Qt applications.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/opengl/framebufferobject2/cubelogo.png b/examples/opengl/framebufferobject2/cubelogo.png
new file mode 100644
index 0000000000..3ae0f9ba3f
--- /dev/null
+++ b/examples/opengl/framebufferobject2/cubelogo.png
Binary files differ
diff --git a/examples/opengl/framebufferobject2/framebufferobject2.pro b/examples/opengl/framebufferobject2/framebufferobject2.pro
new file mode 100644
index 0000000000..cf59cc3679
--- /dev/null
+++ b/examples/opengl/framebufferobject2/framebufferobject2.pro
@@ -0,0 +1,13 @@
+HEADERS += glwidget.h
+SOURCES += glwidget.cpp main.cpp
+RESOURCES += framebufferobject2.qrc
+
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/framebufferobject2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES framebufferobject2.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/framebufferobject2
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/framebufferobject2/framebufferobject2.qrc b/examples/opengl/framebufferobject2/framebufferobject2.qrc
new file mode 100644
index 0000000000..9fc1a56a1a
--- /dev/null
+++ b/examples/opengl/framebufferobject2/framebufferobject2.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>cubelogo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/framebufferobject2/glwidget.cpp b/examples/opengl/framebufferobject2/glwidget.cpp
new file mode 100644
index 0000000000..7a5adf904d
--- /dev/null
+++ b/examples/opengl/framebufferobject2/glwidget.cpp
@@ -0,0 +1,248 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <QtGui/QImage>
+
+#include <math.h>
+
+static GLint cubeArray[][3] = {
+ {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0},
+ {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1},
+ {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1},
+ {0, 1, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 0},
+ {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1},
+ {1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}
+};
+
+static GLint cubeTextureArray[][2] = {
+ {0, 0}, {1, 0}, {1, 1}, {0, 1},
+ {0, 0}, {0, 1}, {1, 1}, {1, 0},
+ {0, 0}, {1, 0}, {1, 1}, {0, 1},
+ {1, 0}, {0, 0}, {0, 1}, {1, 1},
+ {0, 0}, {1, 0}, {1, 1}, {0, 1},
+ {1, 0}, {0, 0}, {0, 1}, {1, 1}
+};
+
+static GLint faceArray[][2] = {
+ {1, -1}, {1, 1}, {-1, 1}, {-1, -1}
+};
+
+static GLubyte colorArray[][4] = {
+ {102, 176, 54, 255},
+ {81, 141, 41, 255},
+ {62, 108, 32, 255},
+ {45, 79, 23, 255}
+};
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ // create the framebuffer object - make sure to have a current
+ // context before creating it
+ makeCurrent();
+ fbo = new QGLFramebufferObject(512, 512);
+ timerId = startTimer(20);
+ setWindowTitle(tr("OpenGL framebuffer objects 2"));
+}
+
+GLWidget::~GLWidget()
+{
+ glDeleteLists(pbufferList, 1);
+ delete fbo;
+}
+
+void GLWidget::initializeGL()
+{
+ glMatrixMode(GL_MODELVIEW);
+
+ glEnable(GL_CULL_FACE);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glVertexPointer(3, GL_INT, 0, cubeArray);
+ glTexCoordPointer(2, GL_INT, 0, cubeTextureArray);
+ glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_DEPTH_TEST);
+
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ pbufferList = glGenLists(1);
+ glNewList(pbufferList, GL_COMPILE);
+ {
+ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+
+ // draw cube background
+ glPushMatrix();
+ glLoadIdentity();
+ glTranslatef(0.5f, 0.5f, -2.0f);
+ glDisable(GL_TEXTURE_2D);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glVertexPointer(2, GL_INT, 0, faceArray);
+ glDrawArrays(GL_QUADS, 0, 4);
+ glVertexPointer(3, GL_INT, 0, cubeArray);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glPopMatrix();
+
+ // draw cube
+ glTranslatef(0.5f, 0.5f, 0.5f);
+ glRotatef(3.0f, 1.0f, 1.0f, 1.0f);
+ glTranslatef(-0.5f, -0.5f, -0.5f);
+ glColor4f(0.9f, 0.9f, 0.9f, 1.0f);
+ glDrawArrays(GL_QUADS, 0, 24);
+
+ glPushMatrix(); // this state is popped back in the paintGL() function
+ }
+ glEndList();
+
+ for (int i = 0; i < 3; ++i) {
+ yOffs[i] = 0.0f;
+ xInc[i] = 0.005f;
+ rot[i] = 0.0f;
+ }
+ xOffs[0]= 0.0f;
+ xOffs[1]= 0.5f;
+ xOffs[2]= 1.0f;
+
+ cubeTexture = bindTexture(QImage(":res/cubelogo.png"));
+
+ glPushMatrix(); // push to avoid stack underflow in the first paintGL() call
+}
+
+void GLWidget::resizeGL(int w, int h)
+{
+ glViewport(0, 0, w, h);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ float aspect = w/(float)(h ? h : 1);
+ glFrustum(-aspect, aspect, -1, 1, 10, 100);
+ glTranslatef(-0.5f, -0.5f, -0.5f);
+ glTranslatef(0.0f, 0.0f, -15.0f);
+}
+
+void GLWidget::paintGL()
+{
+ glPopMatrix(); // pop the matrix pushed in the pbuffer list
+
+ // push the projection matrix and the entire GL state before
+ // doing any rendering into our framebuffer object
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+
+ glViewport(0, 0, fbo->size().width(), fbo->size().height());
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-1, 1, -1, 1, -99, 99);
+ glTranslatef(-0.5f, -0.5f, 0.0f);
+ glMatrixMode(GL_MODELVIEW);
+
+ // render to the framebuffer object
+ fbo->bind();
+ glBindTexture(GL_TEXTURE_2D, cubeTexture);
+ glCallList(pbufferList);
+ fbo->release();
+
+ // pop the projection matrix and GL state back for rendering
+ // to the actual widget
+ glPopAttrib();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+
+ glBindTexture(GL_TEXTURE_2D, fbo->texture());
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ // draw the background
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glVertexPointer(2, GL_INT, 0, faceArray);
+ glTranslatef(-1.2f, -0.8f, 0.0f);
+ glScalef(0.2f, 0.2f, 0.2f);
+ for (int y = 0; y < 5; ++y) {
+ for (int x = 0; x < 5; ++x) {
+ glTranslatef(2.0f, 0, 0);
+ glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
+ glDrawArrays(GL_QUADS, 0, 4);
+ }
+ glTranslatef(-10.0f, 2.0f, 0);
+ }
+ glVertexPointer(3, GL_INT, 0, cubeArray);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+
+ // draw the bouncing cubes
+ drawCube(0, 0.0f, 1.5f, 2.5f, 1.5f);
+ drawCube(1, 1.0f, 2.0f, 2.5f, 2.0f);
+ drawCube(2, 2.0f, 3.5f, 2.5f, 2.5f);
+ glPopMatrix();
+}
+
+void GLWidget::drawCube(int i, GLfloat z, GLfloat rotation, GLfloat jmp, GLfloat amp)
+{
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(xOffs[i], yOffs[i], z);
+ glTranslatef(0.5f, 0.5f, 0.5f);
+ GLfloat scale = 0.75 + i*(0.25f/2);
+ glScalef(scale, scale, scale);
+ glRotatef(rot[i], 1.0f, 1.0f, 1.0f);
+ glTranslatef(-0.5f, -0.5f, -0.5f);
+
+ glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
+ glDrawArrays(GL_QUADS, 0, 24);
+
+ if (xOffs[i] > 1.0f || xOffs[i] < -1.0f) {
+ xInc[i] = -xInc[i];
+ xOffs[i] = xOffs[i] > 1.0f ? 1.0f : -1.0f;
+ }
+ xOffs[i] += xInc[i];
+ yOffs[i] = qAbs(cos((-3.141592f * jmp) * xOffs[i]) * amp) - 1;
+ rot[i] += rotation;
+}
diff --git a/examples/opengl/framebufferobject2/glwidget.h b/examples/opengl/framebufferobject2/glwidget.h
new file mode 100644
index 0000000000..ccb46a3b83
--- /dev/null
+++ b/examples/opengl/framebufferobject2/glwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtOpenGL>
+
+class GLWidget : public QGLWidget
+{
+public:
+ GLWidget(QWidget *parent);
+ ~GLWidget();
+ void initializeGL();
+ void resizeGL(int w, int h);
+ void paintGL();
+ void timerEvent(QTimerEvent *) { update(); }
+ void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
+ void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
+
+ void drawCube(int i, GLfloat z, GLfloat ri, GLfloat jmp, GLfloat amp);
+
+private:
+ GLfloat rot[3], xOffs[3], yOffs[3], xInc[3];
+ GLuint pbufferList;
+ GLuint cubeTexture;
+ int timerId;
+
+ QGLFramebufferObject *fbo;
+};
+
diff --git a/examples/opengl/framebufferobject2/main.cpp b/examples/opengl/framebufferobject2/main.cpp
new file mode 100644
index 0000000000..12e5a62cdd
--- /dev/null
+++ b/examples/opengl/framebufferobject2/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(framebufferobject2);
+
+ QApplication a(argc, argv);
+ if (!QGLFormat::hasOpenGL() || !QGLFramebufferObject::hasOpenGLFramebufferObjects()) {
+ QMessageBox::information(0, "OpenGL framebuffer objects 2",
+ "This system does not support OpenGL/framebuffer objects.");
+ return -1;
+ }
+
+ GLWidget widget(0);
+ widget.resize(640, 480);
+ widget.show();
+ return a.exec();
+}
+
diff --git a/examples/opengl/grabber/glwidget.cpp b/examples/opengl/grabber/glwidget.cpp
new file mode 100644
index 0000000000..72039a7b66
--- /dev/null
+++ b/examples/opengl/grabber/glwidget.cpp
@@ -0,0 +1,283 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include <math.h>
+
+#include "glwidget.h"
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(parent)
+{
+ gear1 = 0;
+ gear2 = 0;
+ gear3 = 0;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+ gear1Rot = 0;
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(advanceGears()));
+ timer->start(20);
+}
+
+GLWidget::~GLWidget()
+{
+ makeCurrent();
+ glDeleteLists(gear1, 1);
+ glDeleteLists(gear2, 1);
+ glDeleteLists(gear3, 1);
+}
+
+void GLWidget::setXRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != xRot) {
+ xRot = angle;
+ emit xRotationChanged(angle);
+ updateGL();
+ }
+}
+
+void GLWidget::setYRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != yRot) {
+ yRot = angle;
+ emit yRotationChanged(angle);
+ updateGL();
+ }
+}
+
+void GLWidget::setZRotation(int angle)
+{
+ normalizeAngle(&angle);
+ if (angle != zRot) {
+ zRot = angle;
+ emit zRotationChanged(angle);
+ updateGL();
+ }
+}
+
+void GLWidget::initializeGL()
+{
+ static const GLfloat lightPos[4] = { 5.0f, 5.0f, 10.0f, 1.0f };
+ static const GLfloat reflectance1[4] = { 0.8f, 0.1f, 0.0f, 1.0f };
+ static const GLfloat reflectance2[4] = { 0.0f, 0.8f, 0.2f, 1.0f };
+ static const GLfloat reflectance3[4] = { 0.2f, 0.2f, 1.0f, 1.0f };
+
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_DEPTH_TEST);
+
+ gear1 = makeGear(reflectance1, 1.0, 4.0, 1.0, 0.7, 20);
+ gear2 = makeGear(reflectance2, 0.5, 2.0, 2.0, 0.7, 10);
+ gear3 = makeGear(reflectance3, 1.3, 2.0, 0.5, 0.7, 10);
+
+ glEnable(GL_NORMALIZE);
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+}
+
+void GLWidget::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glPushMatrix();
+ glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
+ glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
+ glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
+
+ drawGear(gear1, -3.0, -2.0, 0.0, gear1Rot / 16.0);
+ drawGear(gear2, +3.1, -2.0, 0.0, -2.0 * (gear1Rot / 16.0) - 9.0);
+
+ glRotated(+90.0, 1.0, 0.0, 0.0);
+ drawGear(gear3, -3.1, -1.8, -2.2, +2.0 * (gear1Rot / 16.0) - 2.0);
+
+ glPopMatrix();
+}
+
+void GLWidget::resizeGL(int width, int height)
+{
+ int side = qMin(width, height);
+ glViewport((width - side) / 2, (height - side) / 2, side, side);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1.0, +1.0, -1.0, 1.0, 5.0, 60.0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslated(0.0, 0.0, -40.0);
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - lastPos.x();
+ int dy = event->y() - lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ setXRotation(xRot + 8 * dy);
+ setYRotation(yRot + 8 * dx);
+ } else if (event->buttons() & Qt::RightButton) {
+ setXRotation(xRot + 8 * dy);
+ setZRotation(zRot + 8 * dx);
+ }
+ lastPos = event->pos();
+}
+
+void GLWidget::advanceGears()
+{
+ gear1Rot += 2 * 16;
+ updateGL();
+}
+
+GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius,
+ GLdouble outerRadius, GLdouble thickness,
+ GLdouble toothSize, GLint toothCount)
+{
+ const double Pi = 3.14159265358979323846;
+
+ GLuint list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance);
+
+ GLdouble r0 = innerRadius;
+ GLdouble r1 = outerRadius - toothSize / 2.0;
+ GLdouble r2 = outerRadius + toothSize / 2.0;
+ GLdouble delta = (2.0 * Pi / toothCount) / 4.0;
+ GLdouble z = thickness / 2.0;
+ int i, j;
+
+ glShadeModel(GL_FLAT);
+
+ for (i = 0; i < 2; ++i) {
+ GLdouble sign = (i == 0) ? +1.0 : -1.0;
+
+ glNormal3d(0.0, 0.0, sign);
+
+ glBegin(GL_QUAD_STRIP);
+ for (j = 0; j <= toothCount; ++j) {
+ GLdouble angle = 2.0 * Pi * j / toothCount;
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
+ glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z);
+ glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
+ sign * z);
+ }
+ glEnd();
+
+ glBegin(GL_QUADS);
+ for (j = 0; j < toothCount; ++j) {
+ GLdouble angle = 2.0 * Pi * j / toothCount;
+ glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z);
+ glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta),
+ sign * z);
+ glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta),
+ sign * z);
+ glVertex3d(r1 * cos(angle + 3 * delta), r1 * sin(angle + 3 * delta),
+ sign * z);
+ }
+ glEnd();
+ }
+
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i < toothCount; ++i) {
+ for (j = 0; j < 2; ++j) {
+ GLdouble angle = 2.0 * Pi * (i + (j / 2.0)) / toothCount;
+ GLdouble s1 = r1;
+ GLdouble s2 = r2;
+ if (j == 1)
+ qSwap(s1, s2);
+
+ glNormal3d(cos(angle), sin(angle), 0.0);
+ glVertex3d(s1 * cos(angle), s1 * sin(angle), +z);
+ glVertex3d(s1 * cos(angle), s1 * sin(angle), -z);
+
+ glNormal3d(s2 * sin(angle + delta) - s1 * sin(angle),
+ s1 * cos(angle) - s2 * cos(angle + delta), 0.0);
+ glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), +z);
+ glVertex3d(s2 * cos(angle + delta), s2 * sin(angle + delta), -z);
+ }
+ }
+ glVertex3d(r1, 0.0, +z);
+ glVertex3d(r1, 0.0, -z);
+ glEnd();
+
+ glShadeModel(GL_SMOOTH);
+
+ glBegin(GL_QUAD_STRIP);
+ for (i = 0; i <= toothCount; ++i) {
+ GLdouble angle = i * 2.0 * Pi / toothCount;
+ glNormal3d(-cos(angle), -sin(angle), 0.0);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), +z);
+ glVertex3d(r0 * cos(angle), r0 * sin(angle), -z);
+ }
+ glEnd();
+
+ glEndList();
+
+ return list;
+}
+
+void GLWidget::drawGear(GLuint gear, GLdouble dx, GLdouble dy, GLdouble dz,
+ GLdouble angle)
+{
+ glPushMatrix();
+ glTranslated(dx, dy, dz);
+ glRotated(angle, 0.0, 0.0, 1.0);
+ glCallList(gear);
+ glPopMatrix();
+}
+
+void GLWidget::normalizeAngle(int *angle)
+{
+ while (*angle < 0)
+ *angle += 360 * 16;
+ while (*angle > 360 * 16)
+ *angle -= 360 * 16;
+}
diff --git a/examples/opengl/grabber/glwidget.h b/examples/opengl/grabber/glwidget.h
new file mode 100644
index 0000000000..f86d5d06d6
--- /dev/null
+++ b/examples/opengl/grabber/glwidget.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+
+ int xRotation() const { return xRot; }
+ int yRotation() const { return yRot; }
+ int zRotation() const { return zRot; }
+
+public slots:
+ void setXRotation(int angle);
+ void setYRotation(int angle);
+ void setZRotation(int angle);
+
+signals:
+ void xRotationChanged(int angle);
+ void yRotationChanged(int angle);
+ void zRotationChanged(int angle);
+
+protected:
+ void initializeGL();
+ void paintGL();
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+
+private slots:
+ void advanceGears();
+
+private:
+ GLuint makeGear(const GLfloat *reflectance, GLdouble innerRadius,
+ GLdouble outerRadius, GLdouble thickness,
+ GLdouble toothSize, GLint toothCount);
+ void drawGear(GLuint gear, GLdouble dx, GLdouble dy, GLdouble dz,
+ GLdouble angle);
+ void normalizeAngle(int *angle);
+
+ GLuint gear1;
+ GLuint gear2;
+ GLuint gear3;
+ int xRot;
+ int yRot;
+ int zRot;
+ int gear1Rot;
+
+ QPoint lastPos;
+};
+
+#endif
diff --git a/examples/opengl/grabber/grabber.pro b/examples/opengl/grabber/grabber.pro
new file mode 100644
index 0000000000..994026391f
--- /dev/null
+++ b/examples/opengl/grabber/grabber.pro
@@ -0,0 +1,14 @@
+HEADERS = glwidget.h \
+ mainwindow.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ mainwindow.cpp
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/grabber
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS grabber.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/grabber
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/grabber/main.cpp b/examples/opengl/grabber/main.cpp
new file mode 100644
index 0000000000..923c1f8514
--- /dev/null
+++ b/examples/opengl/grabber/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/opengl/grabber/mainwindow.cpp b/examples/opengl/grabber/mainwindow.cpp
new file mode 100644
index 0000000000..d2f3a98dce
--- /dev/null
+++ b/examples/opengl/grabber/mainwindow.cpp
@@ -0,0 +1,206 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include "glwidget.h"
+#include "mainwindow.h"
+
+MainWindow::MainWindow()
+{
+ centralWidget = new QWidget;
+ setCentralWidget(centralWidget);
+
+ glWidget = new GLWidget;
+ pixmapLabel = new QLabel;
+
+ glWidgetArea = new QScrollArea;
+ glWidgetArea->setWidget(glWidget);
+ glWidgetArea->setWidgetResizable(true);
+ glWidgetArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ glWidgetArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ glWidgetArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ glWidgetArea->setMinimumSize(50, 50);
+
+ pixmapLabelArea = new QScrollArea;
+ pixmapLabelArea->setWidget(pixmapLabel);
+ pixmapLabelArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ pixmapLabelArea->setMinimumSize(50, 50);
+
+ xSlider = createSlider(SIGNAL(xRotationChanged(int)),
+ SLOT(setXRotation(int)));
+ ySlider = createSlider(SIGNAL(yRotationChanged(int)),
+ SLOT(setYRotation(int)));
+ zSlider = createSlider(SIGNAL(zRotationChanged(int)),
+ SLOT(setZRotation(int)));
+
+ createActions();
+ createMenus();
+
+ QGridLayout *centralLayout = new QGridLayout;
+ centralLayout->addWidget(glWidgetArea, 0, 0);
+ centralLayout->addWidget(pixmapLabelArea, 0, 1);
+ centralLayout->addWidget(xSlider, 1, 0, 1, 2);
+ centralLayout->addWidget(ySlider, 2, 0, 1, 2);
+ centralLayout->addWidget(zSlider, 3, 0, 1, 2);
+ centralWidget->setLayout(centralLayout);
+
+ xSlider->setValue(15 * 16);
+ ySlider->setValue(345 * 16);
+ zSlider->setValue(0 * 16);
+
+ setWindowTitle(tr("Grabber"));
+ resize(400, 300);
+}
+
+void MainWindow::renderIntoPixmap()
+{
+ QSize size = getSize();
+ if (size.isValid()) {
+ QPixmap pixmap = glWidget->renderPixmap(size.width(), size.height());
+ setPixmap(pixmap);
+ }
+}
+
+void MainWindow::grabFrameBuffer()
+{
+ QImage image = glWidget->grabFrameBuffer();
+ setPixmap(QPixmap::fromImage(image));
+}
+
+void MainWindow::clearPixmap()
+{
+ setPixmap(QPixmap());
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Grabber"),
+ tr("The <b>Grabber</b> example demonstrates two approaches for "
+ "rendering OpenGL into a Qt pixmap."));
+}
+
+void MainWindow::createActions()
+{
+ renderIntoPixmapAct = new QAction(tr("&Render into Pixmap..."), this);
+ renderIntoPixmapAct->setShortcut(tr("Ctrl+R"));
+ connect(renderIntoPixmapAct, SIGNAL(triggered()),
+ this, SLOT(renderIntoPixmap()));
+
+ grabFrameBufferAct = new QAction(tr("&Grab Frame Buffer"), this);
+ grabFrameBufferAct->setShortcut(tr("Ctrl+G"));
+ connect(grabFrameBufferAct, SIGNAL(triggered()),
+ this, SLOT(grabFrameBuffer()));
+
+ clearPixmapAct = new QAction(tr("&Clear Pixmap"), this);
+ clearPixmapAct->setShortcut(tr("Ctrl+L"));
+ connect(clearPixmapAct, SIGNAL(triggered()), this, SLOT(clearPixmap()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(renderIntoPixmapAct);
+ fileMenu->addAction(grabFrameBufferAct);
+ fileMenu->addAction(clearPixmapAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+QSlider *MainWindow::createSlider(const char *changedSignal,
+ const char *setterSlot)
+{
+ QSlider *slider = new QSlider(Qt::Horizontal);
+ slider->setRange(0, 360 * 16);
+ slider->setSingleStep(16);
+ slider->setPageStep(15 * 16);
+ slider->setTickInterval(15 * 16);
+ slider->setTickPosition(QSlider::TicksRight);
+ connect(slider, SIGNAL(valueChanged(int)), glWidget, setterSlot);
+ connect(glWidget, changedSignal, slider, SLOT(setValue(int)));
+ return slider;
+}
+
+void MainWindow::setPixmap(const QPixmap &pixmap)
+{
+ pixmapLabel->setPixmap(pixmap);
+ QSize size = pixmap.size();
+ if (size - QSize(1, 0) == pixmapLabelArea->maximumViewportSize())
+ size -= QSize(1, 0);
+ pixmapLabel->resize(size);
+}
+
+QSize MainWindow::getSize()
+{
+ bool ok;
+ QString text = QInputDialog::getText(this, tr("Grabber"),
+ tr("Enter pixmap size:"),
+ QLineEdit::Normal,
+ tr("%1 x %2").arg(glWidget->width())
+ .arg(glWidget->height()),
+ &ok);
+ if (!ok)
+ return QSize();
+
+ QRegExp regExp(tr("([0-9]+) *x *([0-9]+)"));
+ if (regExp.exactMatch(text)) {
+ int width = regExp.cap(1).toInt();
+ int height = regExp.cap(2).toInt();
+ if (width > 0 && width < 2048 && height > 0 && height < 2048)
+ return QSize(width, height);
+ }
+
+ return glWidget->size();
+}
diff --git a/examples/opengl/grabber/mainwindow.h b/examples/opengl/grabber/mainwindow.h
new file mode 100644
index 0000000000..044d2a8dd7
--- /dev/null
+++ b/examples/opengl/grabber/mainwindow.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QLabel;
+class QMenu;
+class QScrollArea;
+class QSlider;
+QT_END_NAMESPACE
+class GLWidget;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void renderIntoPixmap();
+ void grabFrameBuffer();
+ void clearPixmap();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ QSlider *createSlider(const char *changedSignal, const char *setterSlot);
+ void setPixmap(const QPixmap &pixmap);
+ QSize getSize();
+
+ QWidget *centralWidget;
+ QScrollArea *glWidgetArea;
+ QScrollArea *pixmapLabelArea;
+ GLWidget *glWidget;
+ QLabel *pixmapLabel;
+ QSlider *xSlider;
+ QSlider *ySlider;
+ QSlider *zSlider;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *grabFrameBufferAct;
+ QAction *renderIntoPixmapAct;
+ QAction *clearPixmapAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/opengl/hellogl/glwidget.cpp b/examples/opengl/hellogl/glwidget.cpp
new file mode 100644
index 0000000000..59efb12368
--- /dev/null
+++ b/examples/opengl/hellogl/glwidget.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include <math.h>
+
+#include "glwidget.h"
+#include "qtlogo.h"
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+//! [0]
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ logo = 0;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+
+ qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
+ qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
+}
+//! [0]
+
+//! [1]
+GLWidget::~GLWidget()
+{
+}
+//! [1]
+
+//! [2]
+QSize GLWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+//! [2]
+
+//! [3]
+QSize GLWidget::sizeHint() const
+//! [3] //! [4]
+{
+ return QSize(400, 400);
+}
+//! [4]
+
+static void qNormalizeAngle(int &angle)
+{
+ while (angle < 0)
+ angle += 360 * 16;
+ while (angle > 360 * 16)
+ angle -= 360 * 16;
+}
+
+//! [5]
+void GLWidget::setXRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != xRot) {
+ xRot = angle;
+ emit xRotationChanged(angle);
+ updateGL();
+ }
+}
+//! [5]
+
+void GLWidget::setYRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != yRot) {
+ yRot = angle;
+ emit yRotationChanged(angle);
+ updateGL();
+ }
+}
+
+void GLWidget::setZRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != zRot) {
+ zRot = angle;
+ emit zRotationChanged(angle);
+ updateGL();
+ }
+}
+
+//! [6]
+void GLWidget::initializeGL()
+{
+ qglClearColor(qtPurple.dark());
+
+ logo = new QtLogo(this, 64);
+ logo->setColor(qtGreen.dark());
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_MULTISAMPLE);
+ static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
+}
+//! [6]
+
+//! [7]
+void GLWidget::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+ glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
+ glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
+ glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
+ logo->draw();
+}
+//! [7]
+
+//! [8]
+void GLWidget::resizeGL(int width, int height)
+{
+ int side = qMin(width, height);
+ glViewport((width - side) / 2, (height - side) / 2, side, side);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef QT_OPENGL_ES_1
+ glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
+#else
+ glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
+#endif
+ glMatrixMode(GL_MODELVIEW);
+}
+//! [8]
+
+//! [9]
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ lastPos = event->pos();
+}
+//! [9]
+
+//! [10]
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - lastPos.x();
+ int dy = event->y() - lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ setXRotation(xRot + 8 * dy);
+ setYRotation(yRot + 8 * dx);
+ } else if (event->buttons() & Qt::RightButton) {
+ setXRotation(xRot + 8 * dy);
+ setZRotation(zRot + 8 * dx);
+ }
+ lastPos = event->pos();
+}
+//! [10]
diff --git a/examples/opengl/hellogl/glwidget.h b/examples/opengl/hellogl/glwidget.h
new file mode 100644
index 0000000000..1f12b11e32
--- /dev/null
+++ b/examples/opengl/hellogl/glwidget.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+class QtLogo;
+
+//! [0]
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+//! [0]
+
+//! [1]
+public slots:
+ void setXRotation(int angle);
+ void setYRotation(int angle);
+ void setZRotation(int angle);
+
+signals:
+ void xRotationChanged(int angle);
+ void yRotationChanged(int angle);
+ void zRotationChanged(int angle);
+//! [1]
+
+//! [2]
+protected:
+ void initializeGL();
+ void paintGL();
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+//! [2]
+
+//! [3]
+private:
+ QtLogo *logo;
+ int xRot;
+ int yRot;
+ int zRot;
+ QPoint lastPos;
+ QColor qtGreen;
+ QColor qtPurple;
+};
+//! [3]
+
+#endif
diff --git a/examples/opengl/hellogl/hellogl.pro b/examples/opengl/hellogl/hellogl.pro
new file mode 100644
index 0000000000..fd9699b4cb
--- /dev/null
+++ b/examples/opengl/hellogl/hellogl.pro
@@ -0,0 +1,19 @@
+VPATH += ../shared
+INCLUDEPATH += ../shared
+
+HEADERS = glwidget.h \
+ window.h \
+ qtlogo.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ window.cpp \
+ qtlogo.cpp
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/hellogl/main.cpp b/examples/opengl/hellogl/main.cpp
new file mode 100644
index 0000000000..cc14a70bcc
--- /dev/null
+++ b/examples/opengl/hellogl/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QDesktopWidget>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.resize(window.sizeHint());
+ int desktopArea = QApplication::desktop()->width() *
+ QApplication::desktop()->height();
+ int widgetArea = window.width() * window.height();
+ if (((float)widgetArea / (float)desktopArea) < 0.75f)
+ window.show();
+ else
+ window.showMaximized();
+ return app.exec();
+}
diff --git a/examples/opengl/hellogl/window.cpp b/examples/opengl/hellogl/window.cpp
new file mode 100644
index 0000000000..ef7cc2ad09
--- /dev/null
+++ b/examples/opengl/hellogl/window.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "glwidget.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ glWidget = new GLWidget;
+
+ xSlider = createSlider();
+ ySlider = createSlider();
+ zSlider = createSlider();
+
+ connect(xSlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setXRotation(int)));
+ connect(glWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));
+ connect(ySlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setYRotation(int)));
+ connect(glWidget, SIGNAL(yRotationChanged(int)), ySlider, SLOT(setValue(int)));
+ connect(zSlider, SIGNAL(valueChanged(int)), glWidget, SLOT(setZRotation(int)));
+ connect(glWidget, SIGNAL(zRotationChanged(int)), zSlider, SLOT(setValue(int)));
+//! [0]
+
+//! [1]
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ mainLayout->addWidget(glWidget);
+ mainLayout->addWidget(xSlider);
+ mainLayout->addWidget(ySlider);
+ mainLayout->addWidget(zSlider);
+ setLayout(mainLayout);
+
+ xSlider->setValue(15 * 16);
+ ySlider->setValue(345 * 16);
+ zSlider->setValue(0 * 16);
+ setWindowTitle(tr("Hello GL"));
+}
+//! [1]
+
+//! [2]
+QSlider *Window::createSlider()
+{
+ QSlider *slider = new QSlider(Qt::Vertical);
+ slider->setRange(0, 360 * 16);
+ slider->setSingleStep(16);
+ slider->setPageStep(15 * 16);
+ slider->setTickInterval(15 * 16);
+ slider->setTickPosition(QSlider::TicksRight);
+ return slider;
+}
+//! [2]
+
+void Window::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ close();
+ else
+ QWidget::keyPressEvent(e);
+}
diff --git a/examples/opengl/hellogl/window.h b/examples/opengl/hellogl/window.h
new file mode 100644
index 0000000000..0ac3d64ee4
--- /dev/null
+++ b/examples/opengl/hellogl/window.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QSlider;
+QT_END_NAMESPACE
+//! [0]
+class GLWidget;
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+
+private:
+ QSlider *createSlider();
+
+ GLWidget *glWidget;
+ QSlider *xSlider;
+ QSlider *ySlider;
+ QSlider *zSlider;
+};
+//! [0]
+
+#endif
diff --git a/examples/opengl/hellogl_es/bubble.cpp b/examples/opengl/hellogl_es/bubble.cpp
new file mode 100644
index 0000000000..167d9abd92
--- /dev/null
+++ b/examples/opengl/hellogl_es/bubble.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "bubble.h"
+
+Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
+ : position(position), vel(velocity), radius(radius)
+{
+ innerColor = randomColor();
+ outerColor = randomColor();
+ cache = 0;
+ updateBrush();
+}
+
+//! [0]
+void Bubble::updateCache()
+{
+ if (cache)
+ delete cache;
+ cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32);
+ cache->fill(0x00000000);
+ QPainter p(cache);
+ p.setRenderHint(QPainter::HighQualityAntialiasing);
+ QPen pen(Qt::white);
+ pen.setWidth(2);
+ p.setPen(pen);
+ p.setBrush(brush);
+ p.drawEllipse(0, 0, int(2*radius), int(2*radius));
+}
+//! [0]
+
+Bubble::~Bubble()
+{
+ if (cache)
+ delete cache;
+}
+
+void Bubble::updateBrush()
+{
+ QRadialGradient gradient(QPointF(radius, radius), radius,
+ QPointF(radius*0.5, radius*0.5));
+
+ gradient.setColorAt(0, QColor(255, 255, 255, 255));
+ gradient.setColorAt(0.25, innerColor);
+ gradient.setColorAt(1, outerColor);
+ brush = QBrush(gradient);
+ updateCache();
+}
+
+//! [1]
+void Bubble::drawBubble(QPainter *painter)
+{
+ painter->save();
+ painter->translate(position.x() - radius, position.y() - radius);
+ painter->setOpacity(0.8);
+ painter->drawImage(0, 0, *cache);
+ painter->restore();
+}
+//! [1]
+
+QColor Bubble::randomColor()
+{
+ int red = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
+ int green = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
+ int blue = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
+ int alpha = int(91 + 100.0*qrand()/(RAND_MAX+1.0));
+
+ return QColor(red, green, blue, alpha);
+}
+
+void Bubble::move(const QRect &bbox)
+{
+ position += vel;
+ qreal leftOverflow = position.x() - radius - bbox.left();
+ qreal rightOverflow = position.x() + radius - bbox.right();
+ qreal topOverflow = position.y() - radius - bbox.top();
+ qreal bottomOverflow = position.y() + radius - bbox.bottom();
+
+ if (leftOverflow < 0.0) {
+ position.setX(position.x() - 2 * leftOverflow);
+ vel.setX(-vel.x());
+ } else if (rightOverflow > 0.0) {
+ position.setX(position.x() - 2 * rightOverflow);
+ vel.setX(-vel.x());
+ }
+
+ if (topOverflow < 0.0) {
+ position.setY(position.y() - 2 * topOverflow);
+ vel.setY(-vel.y());
+ } else if (bottomOverflow > 0.0) {
+ position.setY(position.y() - 2 * bottomOverflow);
+ vel.setY(-vel.y());
+ }
+}
+
+QRectF Bubble::rect()
+{
+ return QRectF(position.x() - radius, position.y() - radius,
+ 2 * radius, 2 * radius);
+}
diff --git a/examples/opengl/hellogl_es/bubble.h b/examples/opengl/hellogl_es/bubble.h
new file mode 100644
index 0000000000..21f5add43e
--- /dev/null
+++ b/examples/opengl/hellogl_es/bubble.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BUBBLE_H
+#define BUBBLE_H
+
+#include <QBrush>
+#include <QColor>
+#include <QPointF>
+#include <QRect>
+#include <QRectF>
+
+class QPainter;
+
+class Bubble
+{
+public:
+ Bubble(const QPointF &position, qreal radius, const QPointF &velocity);
+ ~Bubble();
+
+ void drawBubble(QPainter *painter);
+ void updateBrush();
+ void move(const QRect &bbox);
+ void updateCache();
+ QRectF rect();
+
+private:
+ QColor randomColor();
+
+ QBrush brush;
+ QPointF position;
+ QPointF vel;
+ qreal radius;
+ QColor innerColor;
+ QColor outerColor;
+ QImage *cache;
+};
+
+#endif
diff --git a/examples/opengl/hellogl_es/glwidget.cpp b/examples/opengl/hellogl_es/glwidget.cpp
new file mode 100644
index 0000000000..80444dfdbe
--- /dev/null
+++ b/examples/opengl/hellogl_es/glwidget.cpp
@@ -0,0 +1,455 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <QPainter>
+#include <math.h>
+
+#include "bubble.h"
+
+
+const int bubbleNum = 8;
+
+inline void CrossProduct(qreal &xOut, qreal &yOut, qreal &zOut, qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2)
+{
+ xOut = y1 * z2 - z1 * y2;
+ yOut = z1 * x2 - x1 * z2;
+ zOut = x1 * y2 - y1 * x2;
+}
+
+inline void Normalize(qreal &x, qreal &y, qreal &z)
+{
+ qreal l = sqrt(x*x + y*y + z*z);
+ x = x / l;
+ y = y / l;
+ z = z / l;
+}
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(parent)
+{
+ qtLogo = true;
+ createdVertices = 0;
+ createdNormals = 0;
+ m_vertexNumber = 0;
+ frames = 0;
+ setAttribute(Qt::WA_PaintOnScreen);
+ setAttribute(Qt::WA_NoSystemBackground);
+ setAutoBufferSwap(false);
+ m_showBubbles = true;
+}
+
+GLWidget::~GLWidget()
+{
+ if (createdVertices)
+ delete[] createdVertices;
+ if (createdNormals)
+ delete[] createdNormals;
+}
+
+void GLWidget::setScaling(int scale) {
+
+ if (scale > 50)
+ m_fScale = 1 + qreal(scale -50) / 50 * 0.5;
+ else if (scale < 50)
+ m_fScale = 1- (qreal(50 - scale) / 50 * 1/2);
+ else
+ m_fScale = 1;
+}
+
+void GLWidget::setLogo() {
+ qtLogo = true;
+}
+
+void GLWidget::setTexture() {
+ qtLogo = false;
+}
+
+void GLWidget::showBubbles(bool bubbles)
+{
+ m_showBubbles = bubbles;
+}
+
+//! [2]
+void GLWidget::paintQtLogo()
+{
+ glDisable(GL_TEXTURE_2D);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3,GL_FLOAT,0, createdVertices);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(GL_FLOAT,0,createdNormals);
+ glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3);
+}
+//! [2]
+
+void GLWidget::paintTexturedCube()
+{
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, m_uiTexture);
+ GLfloat afVertices[] = {
+ -0.5, 0.5, 0.5, 0.5,-0.5,0.5,-0.5,-0.5,0.5,
+ 0.5, -0.5, 0.5, -0.5,0.5,0.5,0.5,0.5,0.5,
+ -0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
+ 0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,
+
+ 0.5, -0.5, -0.5, 0.5,-0.5,0.5,0.5,0.5,-0.5,
+ 0.5, 0.5, 0.5, 0.5,0.5,-0.5,0.5,-0.5,0.5,
+ -0.5, 0.5, -0.5, -0.5,-0.5,0.5,-0.5,-0.5,-0.5,
+ -0.5, -0.5, 0.5, -0.5,0.5,-0.5,-0.5,0.5,0.5,
+
+ 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5,
+ -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5,
+ -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
+ 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5
+ };
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3,GL_FLOAT,0,afVertices);
+
+ GLfloat afTexCoord[] = {
+ 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
+ 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
+ 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
+ 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
+
+ 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
+ 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
+ 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
+ 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
+
+ 0.0f,1.0f, 1.0f,0.0f, 1.0f,1.0f,
+ 1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f,
+ 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
+ 0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
+ };
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2,GL_FLOAT,0,afTexCoord);
+
+ GLfloat afNormals[] = {
+
+ 0,0,-1, 0,0,-1, 0,0,-1,
+ 0,0,-1, 0,0,-1, 0,0,-1,
+ 0,0,1, 0,0,1, 0,0,1,
+ 0,0,1, 0,0,1, 0,0,1,
+
+ -1,0,0, -1,0,0, -1,0,0,
+ -1,0,0, -1,0,0, -1,0,0,
+ 1,0,0, 1,0,0, 1,0,0,
+ 1,0,0, 1,0,0, 1,0,0,
+
+ 0,-1,0, 0,-1,0, 0,-1,0,
+ 0,-1,0, 0,-1,0, 0,-1,0,
+ 0,1,0, 0,1,0, 0,1,0,
+ 0,1,0, 0,1,0, 0,1,0
+ };
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(GL_FLOAT,0,afNormals);
+
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+}
+
+void GLWidget::initializeGL ()
+{
+ glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+
+ glEnable(GL_TEXTURE_2D);
+ glGenTextures(1, &m_uiTexture);
+ m_uiTexture = bindTexture(QImage(":/qt.png"));
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+ GLfloat aLightPosition[] = {0.0f,0.3f,1.0f,0.0f};
+
+ glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, aLightPosition);
+ m_fAngle = 0;
+ m_fScale = 1;
+ createGeometry();
+ createBubbles(bubbleNum - bubbles.count());
+}
+
+void GLWidget::paintGL()
+{
+ createBubbles(bubbleNum - bubbles.count());
+
+//! [3]
+ QPainter painter;
+ painter.begin(this);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+//! [3]
+
+//! [4]
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+
+ //Since OpenGL ES does not support glPush/PopAttrib(GL_ALL_ATTRIB_BITS)
+ //we have to take care of the states ourselves
+
+ glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_TEXTURE_2D);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+ glShadeModel(GL_FLAT);
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glRotatef(m_fAngle, 0.0f, 1.0f, 0.0f);
+ glRotatef(m_fAngle, 1.0f, 0.0f, 0.0f);
+ glRotatef(m_fAngle, 0.0f, 0.0f, 1.0f);
+ glScalef(m_fScale, m_fScale,m_fScale);
+ glTranslatef(0.0f,-0.2f,0.0f);
+
+ GLfloat matDiff[] = {0.40f, 1.0f, 0.0f, 1.0f};
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiff);
+
+ if (qtLogo)
+ paintQtLogo();
+ else
+ paintTexturedCube();
+//! [4]
+
+//![5]
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+
+ glDisable(GL_LIGHTING);
+ glDisable(GL_LIGHT0);
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+//![5]
+
+//! [6]
+ if (m_showBubbles)
+ foreach (Bubble *bubble, bubbles) {
+ bubble->drawBubble(&painter);
+ }
+//! [6]
+
+//! [7]
+ QString framesPerSecond;
+ framesPerSecond.setNum(frames /(time.elapsed() / 1000.0), 'f', 2);
+
+ painter.setPen(Qt::white);
+
+ painter.drawText(20, 40, framesPerSecond + " fps");
+
+ painter.end();
+//! [7]
+
+//! [8]
+ swapBuffers();
+//! [8]
+
+ QMutableListIterator<Bubble*> iter(bubbles);
+
+ while (iter.hasNext()) {
+ Bubble *bubble = iter.next();
+ bubble->move(rect());
+ }
+ if (!(frames % 100)) {
+ time.start();
+ frames = 0;
+ }
+ m_fAngle += 1.0f;
+ frames ++;
+}
+
+void GLWidget::createBubbles(int number)
+{
+ for (int i = 0; i < number; ++i) {
+ QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
+ height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
+ qreal radius = qMin(width(), height())*(0.0175 + 0.0875*qrand()/(RAND_MAX+1.0));
+ QPointF velocity(width()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)),
+ height()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)));
+
+ bubbles.append(new Bubble(position, radius, velocity));
+ }
+}
+
+void GLWidget::createGeometry()
+{
+ vertices.clear();
+ normals.clear();
+
+ qreal x1 = +0.06f;
+ qreal y1 = -0.14f;
+ qreal x2 = +0.14f;
+ qreal y2 = -0.06f;
+ qreal x3 = +0.08f;
+ qreal y3 = +0.00f;
+ qreal x4 = +0.30f;
+ qreal y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const qreal Pi = 3.14159f;
+ const int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ qreal angle1 = (i * 2 * Pi) / NumSectors;
+ qreal x5 = 0.30 * sin(angle1);
+ qreal y5 = 0.30 * cos(angle1);
+ qreal x6 = 0.20 * sin(angle1);
+ qreal y6 = 0.20 * cos(angle1);
+
+ qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ qreal x7 = 0.20 * sin(angle2);
+ qreal y7 = 0.20 * cos(angle2);
+ qreal x8 = 0.30 * sin(angle2);
+ qreal y8 = 0.30 * cos(angle2);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+//! [1]
+ m_vertexNumber = vertices.size();
+ createdVertices = new GLfloat[m_vertexNumber];
+ createdNormals = new GLfloat[m_vertexNumber];
+ for (int i = 0;i < m_vertexNumber;i++) {
+ createdVertices[i] = vertices.at(i) * 2;
+ createdNormals[i] = normals.at(i);
+ }
+ vertices.clear();
+ normals.clear();
+}
+//! [1]
+
+//! [0]
+void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
+{
+ qreal nx, ny, nz;
+
+ vertices << x1 << y1 << -0.05f;
+ vertices << x2 << y2 << -0.05f;
+ vertices << x4 << y4 << -0.05f;
+
+ vertices << x3 << y3 << -0.05f;
+ vertices << x4 << y4 << -0.05f;
+ vertices << x2 << y2 << -0.05f;
+
+ CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0, x4 - x1, y4 - y1, 0);
+ Normalize(nx, ny, nz);
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+
+ vertices << x4 << y4 << 0.05f;
+ vertices << x2 << y2 << 0.05f;
+ vertices << x1 << y1 << 0.05f;
+
+ vertices << x2 << y2 << 0.05f;
+ vertices << x4 << y4 << 0.05f;
+ vertices << x3 << y3 << 0.05f;
+
+ CrossProduct(nx, ny, nz, x2 - x4, y2 - y4, 0, x1 - x4, y1 - y4, 0);
+ Normalize(nx, ny, nz);
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+}
+//! [0]
+
+void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
+{
+ qreal nx, ny, nz;
+
+ vertices << x1 << y1 << +0.05f;
+ vertices << x2 << y2 << +0.05f;
+ vertices << x1 << y1 << -0.05f;
+
+ vertices << x2 << y2 << -0.05f;
+ vertices << x1 << y1 << -0.05f;
+ vertices << x2 << y2 << +0.05f;
+
+ CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0.0f, 0.0f, 0.0f, -0.1f);
+ Normalize(nx, ny, nz);
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+ normals << nx << ny << nz;
+}
diff --git a/examples/opengl/hellogl_es/glwidget.h b/examples/opengl/hellogl_es/glwidget.h
new file mode 100644
index 0000000000..9908f63fd8
--- /dev/null
+++ b/examples/opengl/hellogl_es/glwidget.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+#include <QTime>
+
+
+
+class Bubble;
+class GLWidget : public QGLWidget {
+
+ Q_OBJECT
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+public slots:
+ void setScaling(int scale);
+ void setLogo();
+ void setTexture();
+ void showBubbles(bool);
+protected:
+ void paintGL ();
+ void initializeGL ();
+private:
+ GLuint m_uiTexture;
+ qreal m_fAngle;
+ qreal m_fScale;
+ bool m_showBubbles;
+ void paintTexturedCube();
+ void paintQtLogo();
+ void createGeometry();
+ void createBubbles(int number);
+ void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
+ void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
+ QList<qreal> vertices;
+ QList<qreal> normals;
+ GLfloat *createdVertices;
+ GLfloat *createdNormals;
+ int m_vertexNumber;
+ bool qtLogo;
+ QList<Bubble*> bubbles;
+ int frames;
+ QTime time;
+};
+#endif
diff --git a/examples/opengl/hellogl_es/hellogl_es.pro b/examples/opengl/hellogl_es/hellogl_es.pro
new file mode 100644
index 0000000000..774bfef265
--- /dev/null
+++ b/examples/opengl/hellogl_es/hellogl_es.pro
@@ -0,0 +1,27 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Thu Oct 4 19:01:12 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+SOURCES += glwidget.cpp
+SOURCES += mainwindow.cpp
+SOURCES += bubble.cpp
+
+HEADERS += glwidget.h
+HEADERS += mainwindow.h
+HEADERS += bubble.h
+
+RESOURCES += texture.qrc
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl_es
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl_es.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl_es
+INSTALLS += target sources
diff --git a/examples/opengl/hellogl_es/main.cpp b/examples/opengl/hellogl_es/main.cpp
new file mode 100644
index 0000000000..5693d7ad55
--- /dev/null
+++ b/examples/opengl/hellogl_es/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMainWindow>
+#include "mainwindow.h"
+
+int main( int argc, char ** argv )
+{
+ Q_INIT_RESOURCE(texture);
+ QApplication a( argc, argv );
+ MainWindow mw;
+ mw.showMaximized();
+ return a.exec();
+}
diff --git a/examples/opengl/hellogl_es/mainwindow.cpp b/examples/opengl/hellogl_es/mainwindow.cpp
new file mode 100644
index 0000000000..cd253fcd19
--- /dev/null
+++ b/examples/opengl/hellogl_es/mainwindow.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QApplication>
+#include <QMenuBar>
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QSlider>
+#include <QLabel>
+#include <QTimer>
+
+#include "glwidget.h"
+
+MainWindow::MainWindow()
+{
+ GLWidget *glwidget = new GLWidget();
+ QLabel *label = new QLabel(this);
+ QTimer *timer = new QTimer(this);
+ QSlider *slider = new QSlider(this);
+ slider->setOrientation(Qt::Horizontal);
+
+ slider->setRange(0, 100);
+ slider->setSliderPosition(50);
+ timer->setInterval(10);
+ label->setText("A QGlWidget with OpenGl ES");
+ label->setAlignment(Qt::AlignHCenter);
+
+ QGroupBox * groupBox = new QGroupBox(this);
+ setCentralWidget(groupBox);
+ groupBox->setTitle("OpenGL ES Example");
+
+ QGridLayout *layout = new QGridLayout(groupBox);
+
+ layout->addWidget(glwidget,1,0,8,1);
+ layout->addWidget(label,9,0,1,1);
+ layout->addWidget(slider, 11,0,1,1);
+
+ groupBox->setLayout(layout);
+
+ QMenu *fileMenu = new QMenu("File");
+ QMenu *helpMenu = new QMenu("Help");
+ QMenu *showMenu = new QMenu("Show");
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(showMenu);
+ menuBar()->addMenu(helpMenu);
+ QAction *exit = new QAction("Exit", fileMenu);
+ QAction *aboutQt = new QAction("AboutQt", helpMenu);
+ QAction *showLogo = new QAction("Show 3D Logo", showMenu);
+ QAction *showTexture = new QAction("Show 2D Texture", showMenu);
+ QAction *showBubbles = new QAction("Show bubbles", showMenu);
+ showBubbles->setCheckable(true);
+ showBubbles->setChecked(true);
+ fileMenu->addAction(exit);
+ helpMenu->addAction(aboutQt);
+ showMenu->addAction(showLogo);
+ showMenu->addAction(showTexture);
+ showMenu->addAction(showBubbles);
+
+ QObject::connect(timer, SIGNAL(timeout()), glwidget, SLOT(updateGL()));
+ QObject::connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
+ QObject::connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
+
+ QObject::connect(showLogo, SIGNAL(triggered(bool)), glwidget, SLOT(setLogo()));
+ QObject::connect(showTexture, SIGNAL(triggered(bool)), glwidget, SLOT(setTexture()));
+ QObject::connect(showBubbles, SIGNAL(triggered(bool)), glwidget, SLOT(showBubbles(bool)));
+ QObject::connect(slider, SIGNAL(valueChanged(int)), glwidget, SLOT(setScaling(int)));
+ timer->start();
+}
diff --git a/examples/opengl/hellogl_es/mainwindow.h b/examples/opengl/hellogl_es/mainwindow.h
new file mode 100644
index 0000000000..a0a6adfc3c
--- /dev/null
+++ b/examples/opengl/hellogl_es/mainwindow.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class QSlider;
+class GLWidget;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private:
+};
+
+#endif
diff --git a/examples/opengl/hellogl_es/qt.png b/examples/opengl/hellogl_es/qt.png
new file mode 100644
index 0000000000..79e383cf50
--- /dev/null
+++ b/examples/opengl/hellogl_es/qt.png
Binary files differ
diff --git a/examples/opengl/hellogl_es/texture.qrc b/examples/opengl/hellogl_es/texture.qrc
new file mode 100644
index 0000000000..ff1d0e535f
--- /dev/null
+++ b/examples/opengl/hellogl_es/texture.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>qt.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/hellogl_es2/bubble.cpp b/examples/opengl/hellogl_es2/bubble.cpp
new file mode 100644
index 0000000000..167d9abd92
--- /dev/null
+++ b/examples/opengl/hellogl_es2/bubble.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "bubble.h"
+
+Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
+ : position(position), vel(velocity), radius(radius)
+{
+ innerColor = randomColor();
+ outerColor = randomColor();
+ cache = 0;
+ updateBrush();
+}
+
+//! [0]
+void Bubble::updateCache()
+{
+ if (cache)
+ delete cache;
+ cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32);
+ cache->fill(0x00000000);
+ QPainter p(cache);
+ p.setRenderHint(QPainter::HighQualityAntialiasing);
+ QPen pen(Qt::white);
+ pen.setWidth(2);
+ p.setPen(pen);
+ p.setBrush(brush);
+ p.drawEllipse(0, 0, int(2*radius), int(2*radius));
+}
+//! [0]
+
+Bubble::~Bubble()
+{
+ if (cache)
+ delete cache;
+}
+
+void Bubble::updateBrush()
+{
+ QRadialGradient gradient(QPointF(radius, radius), radius,
+ QPointF(radius*0.5, radius*0.5));
+
+ gradient.setColorAt(0, QColor(255, 255, 255, 255));
+ gradient.setColorAt(0.25, innerColor);
+ gradient.setColorAt(1, outerColor);
+ brush = QBrush(gradient);
+ updateCache();
+}
+
+//! [1]
+void Bubble::drawBubble(QPainter *painter)
+{
+ painter->save();
+ painter->translate(position.x() - radius, position.y() - radius);
+ painter->setOpacity(0.8);
+ painter->drawImage(0, 0, *cache);
+ painter->restore();
+}
+//! [1]
+
+QColor Bubble::randomColor()
+{
+ int red = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
+ int green = int(185 + 70.0*qrand()/(RAND_MAX+1.0));
+ int blue = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
+ int alpha = int(91 + 100.0*qrand()/(RAND_MAX+1.0));
+
+ return QColor(red, green, blue, alpha);
+}
+
+void Bubble::move(const QRect &bbox)
+{
+ position += vel;
+ qreal leftOverflow = position.x() - radius - bbox.left();
+ qreal rightOverflow = position.x() + radius - bbox.right();
+ qreal topOverflow = position.y() - radius - bbox.top();
+ qreal bottomOverflow = position.y() + radius - bbox.bottom();
+
+ if (leftOverflow < 0.0) {
+ position.setX(position.x() - 2 * leftOverflow);
+ vel.setX(-vel.x());
+ } else if (rightOverflow > 0.0) {
+ position.setX(position.x() - 2 * rightOverflow);
+ vel.setX(-vel.x());
+ }
+
+ if (topOverflow < 0.0) {
+ position.setY(position.y() - 2 * topOverflow);
+ vel.setY(-vel.y());
+ } else if (bottomOverflow > 0.0) {
+ position.setY(position.y() - 2 * bottomOverflow);
+ vel.setY(-vel.y());
+ }
+}
+
+QRectF Bubble::rect()
+{
+ return QRectF(position.x() - radius, position.y() - radius,
+ 2 * radius, 2 * radius);
+}
diff --git a/examples/opengl/hellogl_es2/bubble.h b/examples/opengl/hellogl_es2/bubble.h
new file mode 100644
index 0000000000..21f5add43e
--- /dev/null
+++ b/examples/opengl/hellogl_es2/bubble.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BUBBLE_H
+#define BUBBLE_H
+
+#include <QBrush>
+#include <QColor>
+#include <QPointF>
+#include <QRect>
+#include <QRectF>
+
+class QPainter;
+
+class Bubble
+{
+public:
+ Bubble(const QPointF &position, qreal radius, const QPointF &velocity);
+ ~Bubble();
+
+ void drawBubble(QPainter *painter);
+ void updateBrush();
+ void move(const QRect &bbox);
+ void updateCache();
+ QRectF rect();
+
+private:
+ QColor randomColor();
+
+ QBrush brush;
+ QPointF position;
+ QPointF vel;
+ qreal radius;
+ QColor innerColor;
+ QColor outerColor;
+ QImage *cache;
+};
+
+#endif
diff --git a/examples/opengl/hellogl_es2/glwidget.cpp b/examples/opengl/hellogl_es2/glwidget.cpp
new file mode 100644
index 0000000000..90c322bdec
--- /dev/null
+++ b/examples/opengl/hellogl_es2/glwidget.cpp
@@ -0,0 +1,463 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <QPainter>
+#include <QPaintEngine>
+#include <math.h>
+
+#include "bubble.h"
+
+
+const int bubbleNum = 8;
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(parent)
+{
+ qtLogo = true;
+ frames = 0;
+ setAttribute(Qt::WA_PaintOnScreen);
+ setAttribute(Qt::WA_NoSystemBackground);
+ setAutoBufferSwap(false);
+ m_showBubbles = true;
+#ifndef Q_WS_QWS
+ setMinimumSize(300, 250);
+#endif
+}
+
+GLWidget::~GLWidget()
+{
+}
+
+void GLWidget::setScaling(int scale) {
+
+ if (scale > 50)
+ m_fScale = 1 + qreal(scale -50) / 50 * 0.5;
+ else if (scale < 50)
+ m_fScale = 1- (qreal(50 - scale) / 50 * 1/2);
+ else
+ m_fScale = 1;
+}
+
+void GLWidget::setLogo() {
+ qtLogo = true;
+}
+
+void GLWidget::setTexture() {
+ qtLogo = false;
+}
+
+void GLWidget::showBubbles(bool bubbles)
+{
+ m_showBubbles = bubbles;
+}
+
+void GLWidget::paintQtLogo()
+{
+ program1.enableAttributeArray(normalAttr1);
+ program1.enableAttributeArray(vertexAttr1);
+ program1.setAttributeArray(vertexAttr1, vertices.constData());
+ program1.setAttributeArray(normalAttr1, normals.constData());
+ glDrawArrays(GL_TRIANGLES, 0, vertices.size());
+ program1.disableAttributeArray(normalAttr1);
+ program1.disableAttributeArray(vertexAttr1);
+}
+
+void GLWidget::paintTexturedCube()
+{
+ glBindTexture(GL_TEXTURE_2D, m_uiTexture);
+ GLfloat afVertices[] = {
+ -0.5, 0.5, 0.5, 0.5,-0.5,0.5,-0.5,-0.5,0.5,
+ 0.5, -0.5, 0.5, -0.5,0.5,0.5,0.5,0.5,0.5,
+ -0.5, -0.5, -0.5, 0.5,-0.5,-0.5,-0.5,0.5,-0.5,
+ 0.5, 0.5, -0.5, -0.5,0.5,-0.5,0.5,-0.5,-0.5,
+
+ 0.5, -0.5, -0.5, 0.5,-0.5,0.5,0.5,0.5,-0.5,
+ 0.5, 0.5, 0.5, 0.5,0.5,-0.5,0.5,-0.5,0.5,
+ -0.5, 0.5, -0.5, -0.5,-0.5,0.5,-0.5,-0.5,-0.5,
+ -0.5, -0.5, 0.5, -0.5,0.5,-0.5,-0.5,0.5,0.5,
+
+ 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5,
+ -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5,
+ -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5,
+ 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5
+ };
+ program2.setAttributeArray(vertexAttr2, afVertices, 3);
+
+ GLfloat afTexCoord[] = {
+ 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
+ 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
+ 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
+ 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
+
+ 1.0f,1.0f, 1.0f,0.0f, 0.0f,1.0f,
+ 0.0f,0.0f, 0.0f,1.0f, 1.0f,0.0f,
+ 0.0f,0.0f, 1.0f,1.0f, 1.0f,0.0f,
+ 1.0f,1.0f, 0.0f,0.0f, 0.0f,1.0f,
+
+ 0.0f,1.0f, 1.0f,0.0f, 1.0f,1.0f,
+ 1.0f,0.0f, 0.0f,1.0f, 0.0f,0.0f,
+ 1.0f,0.0f, 1.0f,1.0f, 0.0f,0.0f,
+ 0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
+ };
+ program2.setAttributeArray(texCoordAttr2, afTexCoord, 2);
+
+ GLfloat afNormals[] = {
+
+ 0,0,-1, 0,0,-1, 0,0,-1,
+ 0,0,-1, 0,0,-1, 0,0,-1,
+ 0,0,1, 0,0,1, 0,0,1,
+ 0,0,1, 0,0,1, 0,0,1,
+
+ -1,0,0, -1,0,0, -1,0,0,
+ -1,0,0, -1,0,0, -1,0,0,
+ 1,0,0, 1,0,0, 1,0,0,
+ 1,0,0, 1,0,0, 1,0,0,
+
+ 0,-1,0, 0,-1,0, 0,-1,0,
+ 0,-1,0, 0,-1,0, 0,-1,0,
+ 0,1,0, 0,1,0, 0,1,0,
+ 0,1,0, 0,1,0, 0,1,0
+ };
+ program2.setAttributeArray(normalAttr2, afNormals, 3);
+
+ program2.setUniformValue(textureUniform2, 0); // use texture unit 0
+
+ program2.enableAttributeArray(vertexAttr2);
+ program2.enableAttributeArray(normalAttr2);
+ program2.enableAttributeArray(texCoordAttr2);
+
+ glDrawArrays(GL_TRIANGLES, 0, 36);
+
+ program2.disableAttributeArray(vertexAttr2);
+ program2.disableAttributeArray(normalAttr2);
+ program2.disableAttributeArray(texCoordAttr2);
+}
+
+void GLWidget::initializeGL ()
+{
+ glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+
+ glGenTextures(1, &m_uiTexture);
+ m_uiTexture = bindTexture(QImage(":/qt.png"));
+
+ QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
+ const char *vsrc1 =
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump vec3 normal;\n"
+ "uniform mediump mat4 matrix;\n"
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
+ " float angle = max(dot(normal, toLight), 0.0);\n"
+ " vec3 col = vec3(0.40, 1.0, 0.0);\n"
+ " color = vec4(col * 0.2 + col * 0.8 * angle, 1.0);\n"
+ " color = clamp(color, 0.0, 1.0);\n"
+ " gl_Position = matrix * vertex;\n"
+ "}\n";
+ vshader1->compileSourceCode(vsrc1);
+
+ QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
+ const char *fsrc1 =
+ "varying mediump vec4 color;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+ fshader1->compileSourceCode(fsrc1);
+
+ program1.addShader(vshader1);
+ program1.addShader(fshader1);
+ program1.link();
+
+ vertexAttr1 = program1.attributeLocation("vertex");
+ normalAttr1 = program1.attributeLocation("normal");
+ matrixUniform1 = program1.uniformLocation("matrix");
+
+ QGLShader *vshader2 = new QGLShader(QGLShader::Vertex);
+ const char *vsrc2 =
+ "attribute highp vec4 vertex;\n"
+ "attribute highp vec4 texCoord;\n"
+ "attribute mediump vec3 normal;\n"
+ "uniform mediump mat4 matrix;\n"
+ "varying highp vec4 texc;\n"
+ "varying mediump float angle;\n"
+ "void main(void)\n"
+ "{\n"
+ " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
+ " angle = max(dot(normal, toLight), 0.0);\n"
+ " gl_Position = matrix * vertex;\n"
+ " texc = texCoord;\n"
+ "}\n";
+ vshader2->compileSourceCode(vsrc2);
+
+ QGLShader *fshader2 = new QGLShader(QGLShader::Fragment);
+ const char *fsrc2 =
+ "varying highp vec4 texc;\n"
+ "uniform sampler2D tex;\n"
+ "varying mediump float angle;\n"
+ "void main(void)\n"
+ "{\n"
+ " highp vec3 color = texture2D(tex, texc.st).rgb;\n"
+ " color = color * 0.2 + color * 0.8 * angle;\n"
+ " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
+ "}\n";
+ fshader2->compileSourceCode(fsrc2);
+
+ program2.addShader(vshader2);
+ program2.addShader(fshader2);
+ program2.link();
+
+ vertexAttr2 = program2.attributeLocation("vertex");
+ normalAttr2 = program2.attributeLocation("normal");
+ texCoordAttr2 = program2.attributeLocation("texCoord");
+ matrixUniform2 = program2.uniformLocation("matrix");
+ textureUniform2 = program2.uniformLocation("tex");
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+ m_fAngle = 0;
+ m_fScale = 1;
+ createGeometry();
+ createBubbles(bubbleNum - bubbles.count());
+}
+
+void GLWidget::paintGL()
+{
+ createBubbles(bubbleNum - bubbles.count());
+
+ QPainter painter;
+ painter.begin(this);
+
+ painter.beginNativePainting();
+
+ glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+ glFrontFace(GL_CW);
+ glCullFace(GL_FRONT);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+
+ QMatrix4x4 modelview;
+ modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
+ modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
+ modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
+ modelview.scale(m_fScale);
+ modelview.translate(0.0f, -0.2f, 0.0f);
+
+ if (qtLogo) {
+ program1.bind();
+ program1.setUniformValue(matrixUniform1, modelview);
+ paintQtLogo();
+ program1.release();
+ } else {
+ program2.bind();
+ program1.setUniformValue(matrixUniform2, modelview);
+ paintTexturedCube();
+ program2.release();
+ }
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+
+ painter.endNativePainting();
+
+ if (m_showBubbles)
+ foreach (Bubble *bubble, bubbles) {
+ bubble->drawBubble(&painter);
+ }
+
+ QString framesPerSecond;
+ framesPerSecond.setNum(frames /(time.elapsed() / 1000.0), 'f', 2);
+
+ painter.setPen(Qt::white);
+
+ painter.drawText(20, 40, framesPerSecond + " fps");
+
+ painter.end();
+
+ swapBuffers();
+
+ QMutableListIterator<Bubble*> iter(bubbles);
+
+ while (iter.hasNext()) {
+ Bubble *bubble = iter.next();
+ bubble->move(rect());
+ }
+ if (!(frames % 100)) {
+ time.start();
+ frames = 0;
+ }
+ m_fAngle += 1.0f;
+ frames ++;
+}
+
+void GLWidget::createBubbles(int number)
+{
+ for (int i = 0; i < number; ++i) {
+ QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
+ height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
+ qreal radius = qMin(width(), height())*(0.0175 + 0.0875*qrand()/(RAND_MAX+1.0));
+ QPointF velocity(width()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)),
+ height()*0.0175*(-0.5 + qrand()/(RAND_MAX+1.0)));
+
+ bubbles.append(new Bubble(position, radius, velocity));
+ }
+}
+
+void GLWidget::createGeometry()
+{
+ vertices.clear();
+ normals.clear();
+
+ qreal x1 = +0.06f;
+ qreal y1 = -0.14f;
+ qreal x2 = +0.14f;
+ qreal y2 = -0.06f;
+ qreal x3 = +0.08f;
+ qreal y3 = +0.00f;
+ qreal x4 = +0.30f;
+ qreal y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const qreal Pi = 3.14159f;
+ const int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ qreal angle1 = (i * 2 * Pi) / NumSectors;
+ qreal x5 = 0.30 * sin(angle1);
+ qreal y5 = 0.30 * cos(angle1);
+ qreal x6 = 0.20 * sin(angle1);
+ qreal y6 = 0.20 * cos(angle1);
+
+ qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ qreal x7 = 0.20 * sin(angle2);
+ qreal y7 = 0.20 * cos(angle2);
+ qreal x8 = 0.30 * sin(angle2);
+ qreal y8 = 0.30 * cos(angle2);
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+
+ for (int i = 0;i < vertices.size();i++)
+ vertices[i] *= 2.0f;
+}
+
+void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
+{
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
+
+ vertices << QVector3D(x3, y3, -0.05f);
+ vertices << QVector3D(x4, y4, -0.05f);
+ vertices << QVector3D(x2, y2, -0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x1, y1, 0.05f);
+
+ vertices << QVector3D(x2, y2, 0.05f);
+ vertices << QVector3D(x4, y4, 0.05f);
+ vertices << QVector3D(x3, y3, 0.05f);
+
+ n = QVector3D::normal
+ (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+}
+
+void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
+{
+ vertices << QVector3D(x1, y1, +0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
+
+ vertices << QVector3D(x2, y2, -0.05f);
+ vertices << QVector3D(x1, y1, -0.05f);
+ vertices << QVector3D(x2, y2, +0.05f);
+
+ QVector3D n = QVector3D::normal
+ (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
+
+ normals << n;
+ normals << n;
+ normals << n;
+
+ normals << n;
+ normals << n;
+ normals << n;
+}
diff --git a/examples/opengl/hellogl_es2/glwidget.h b/examples/opengl/hellogl_es2/glwidget.h
new file mode 100644
index 0000000000..44b78d6120
--- /dev/null
+++ b/examples/opengl/hellogl_es2/glwidget.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qmatrix4x4.h>
+#include <QtOpenGL/qglshaderprogram.h>
+#include <QTime>
+#include <QVector>
+
+class Bubble;
+class GLWidget : public QGLWidget {
+
+ Q_OBJECT
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+public slots:
+ void setScaling(int scale);
+ void setLogo();
+ void setTexture();
+ void showBubbles(bool);
+protected:
+ void paintGL ();
+ void initializeGL ();
+private:
+ GLuint m_uiTexture;
+ qreal m_fAngle;
+ qreal m_fScale;
+ bool m_showBubbles;
+ void paintTexturedCube();
+ void paintQtLogo();
+ void createGeometry();
+ void createBubbles(int number);
+ void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
+ void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
+ QVector<QVector3D> vertices;
+ QVector<QVector3D> normals;
+ bool qtLogo;
+ QList<Bubble*> bubbles;
+ int frames;
+ QTime time;
+ QGLShaderProgram program1;
+ QGLShaderProgram program2;
+ int vertexAttr1;
+ int normalAttr1;
+ int matrixUniform1;
+ int vertexAttr2;
+ int normalAttr2;
+ int texCoordAttr2;
+ int matrixUniform2;
+ int textureUniform2;
+};
+#endif
diff --git a/examples/opengl/hellogl_es2/hellogl_es2.pro b/examples/opengl/hellogl_es2/hellogl_es2.pro
new file mode 100644
index 0000000000..8016aa37b0
--- /dev/null
+++ b/examples/opengl/hellogl_es2/hellogl_es2.pro
@@ -0,0 +1,27 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Thu Oct 4 19:01:12 2007
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+SOURCES += glwidget.cpp
+SOURCES += mainwindow.cpp
+SOURCES += bubble.cpp
+
+HEADERS += glwidget.h
+HEADERS += mainwindow.h
+HEADERS += bubble.h
+
+RESOURCES += texture.qrc
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl_es2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellogl_es2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/hellogl_es2
+INSTALLS += target sources
diff --git a/examples/opengl/hellogl_es2/main.cpp b/examples/opengl/hellogl_es2/main.cpp
new file mode 100644
index 0000000000..5693d7ad55
--- /dev/null
+++ b/examples/opengl/hellogl_es2/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMainWindow>
+#include "mainwindow.h"
+
+int main( int argc, char ** argv )
+{
+ Q_INIT_RESOURCE(texture);
+ QApplication a( argc, argv );
+ MainWindow mw;
+ mw.showMaximized();
+ return a.exec();
+}
diff --git a/examples/opengl/hellogl_es2/mainwindow.cpp b/examples/opengl/hellogl_es2/mainwindow.cpp
new file mode 100644
index 0000000000..cd253fcd19
--- /dev/null
+++ b/examples/opengl/hellogl_es2/mainwindow.cpp
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QApplication>
+#include <QMenuBar>
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QSlider>
+#include <QLabel>
+#include <QTimer>
+
+#include "glwidget.h"
+
+MainWindow::MainWindow()
+{
+ GLWidget *glwidget = new GLWidget();
+ QLabel *label = new QLabel(this);
+ QTimer *timer = new QTimer(this);
+ QSlider *slider = new QSlider(this);
+ slider->setOrientation(Qt::Horizontal);
+
+ slider->setRange(0, 100);
+ slider->setSliderPosition(50);
+ timer->setInterval(10);
+ label->setText("A QGlWidget with OpenGl ES");
+ label->setAlignment(Qt::AlignHCenter);
+
+ QGroupBox * groupBox = new QGroupBox(this);
+ setCentralWidget(groupBox);
+ groupBox->setTitle("OpenGL ES Example");
+
+ QGridLayout *layout = new QGridLayout(groupBox);
+
+ layout->addWidget(glwidget,1,0,8,1);
+ layout->addWidget(label,9,0,1,1);
+ layout->addWidget(slider, 11,0,1,1);
+
+ groupBox->setLayout(layout);
+
+ QMenu *fileMenu = new QMenu("File");
+ QMenu *helpMenu = new QMenu("Help");
+ QMenu *showMenu = new QMenu("Show");
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(showMenu);
+ menuBar()->addMenu(helpMenu);
+ QAction *exit = new QAction("Exit", fileMenu);
+ QAction *aboutQt = new QAction("AboutQt", helpMenu);
+ QAction *showLogo = new QAction("Show 3D Logo", showMenu);
+ QAction *showTexture = new QAction("Show 2D Texture", showMenu);
+ QAction *showBubbles = new QAction("Show bubbles", showMenu);
+ showBubbles->setCheckable(true);
+ showBubbles->setChecked(true);
+ fileMenu->addAction(exit);
+ helpMenu->addAction(aboutQt);
+ showMenu->addAction(showLogo);
+ showMenu->addAction(showTexture);
+ showMenu->addAction(showBubbles);
+
+ QObject::connect(timer, SIGNAL(timeout()), glwidget, SLOT(updateGL()));
+ QObject::connect(exit, SIGNAL(triggered(bool)), this, SLOT(close()));
+ QObject::connect(aboutQt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
+
+ QObject::connect(showLogo, SIGNAL(triggered(bool)), glwidget, SLOT(setLogo()));
+ QObject::connect(showTexture, SIGNAL(triggered(bool)), glwidget, SLOT(setTexture()));
+ QObject::connect(showBubbles, SIGNAL(triggered(bool)), glwidget, SLOT(showBubbles(bool)));
+ QObject::connect(slider, SIGNAL(valueChanged(int)), glwidget, SLOT(setScaling(int)));
+ timer->start();
+}
diff --git a/examples/opengl/hellogl_es2/mainwindow.h b/examples/opengl/hellogl_es2/mainwindow.h
new file mode 100644
index 0000000000..a0a6adfc3c
--- /dev/null
+++ b/examples/opengl/hellogl_es2/mainwindow.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class QSlider;
+class GLWidget;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private:
+};
+
+#endif
diff --git a/examples/opengl/hellogl_es2/qt.png b/examples/opengl/hellogl_es2/qt.png
new file mode 100644
index 0000000000..79e383cf50
--- /dev/null
+++ b/examples/opengl/hellogl_es2/qt.png
Binary files differ
diff --git a/examples/opengl/hellogl_es2/texture.qrc b/examples/opengl/hellogl_es2/texture.qrc
new file mode 100644
index 0000000000..ff1d0e535f
--- /dev/null
+++ b/examples/opengl/hellogl_es2/texture.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>qt.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro
new file mode 100644
index 0000000000..77b6fa13aa
--- /dev/null
+++ b/examples/opengl/opengl.pro
@@ -0,0 +1,35 @@
+TEMPLATE = subdirs
+
+contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles2){
+ contains(QT_CONFIG, opengles2) {
+ SUBDIRS = hellogl_es2
+ } else {
+ SUBDIRS = hellogl_es
+ }
+ SUBDIRS += textures
+ contains(QT_CONFIG, opengles1) {
+ SUBDIRS += hellogl
+ }
+} else {
+ SUBDIRS = 2dpainting \
+ grabber \
+ hellogl \
+ overpainting \
+ pbuffers \
+ framebufferobject2 \
+ samplebuffers \
+ textures
+
+ contains(QT_CONFIG, svg) {
+ SUBDIRS += framebufferobject \
+ pbuffers2
+ }
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS opengl.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/overpainting/bubble.cpp b/examples/opengl/overpainting/bubble.cpp
new file mode 100644
index 0000000000..eb315057fa
--- /dev/null
+++ b/examples/opengl/overpainting/bubble.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "bubble.h"
+
+Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
+ : position(position), vel(velocity), radius(radius)
+{
+ innerColor = randomColor();
+ outerColor = randomColor();
+ updateBrush();
+}
+
+void Bubble::updateBrush()
+{
+ QRadialGradient gradient(QPointF(radius, radius), radius,
+ QPointF(radius*0.5, radius*0.5));
+
+ gradient.setColorAt(0, QColor(255, 255, 255, 255));
+ gradient.setColorAt(0.25, innerColor);
+ gradient.setColorAt(1, outerColor);
+ brush = QBrush(gradient);
+}
+
+void Bubble::drawBubble(QPainter *painter)
+{
+ painter->save();
+ painter->translate(position.x() - radius, position.y() - radius);
+ painter->setBrush(brush);
+ painter->drawEllipse(0, 0, int(2*radius), int(2*radius));
+ painter->restore();
+}
+
+QColor Bubble::randomColor()
+{
+ int red = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
+ int green = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
+ int blue = int(205 + 50.0*qrand()/(RAND_MAX+1.0));
+ int alpha = int(91 + 100.0*qrand()/(RAND_MAX+1.0));
+
+ return QColor(red, green, blue, alpha);
+}
+
+void Bubble::move(const QRect &bbox)
+{
+ position += vel;
+ qreal leftOverflow = position.x() - radius - bbox.left();
+ qreal rightOverflow = position.x() + radius - bbox.right();
+ qreal topOverflow = position.y() - radius - bbox.top();
+ qreal bottomOverflow = position.y() + radius - bbox.bottom();
+
+ if (leftOverflow < 0.0) {
+ position.setX(position.x() - 2 * leftOverflow);
+ vel.setX(-vel.x());
+ } else if (rightOverflow > 0.0) {
+ position.setX(position.x() - 2 * rightOverflow);
+ vel.setX(-vel.x());
+ }
+
+ if (topOverflow < 0.0) {
+ position.setY(position.y() - 2 * topOverflow);
+ vel.setY(-vel.y());
+ } else if (bottomOverflow > 0.0) {
+ position.setY(position.y() - 2 * bottomOverflow);
+ vel.setY(-vel.y());
+ }
+}
+
+QRectF Bubble::rect()
+{
+ return QRectF(position.x() - radius, position.y() - radius,
+ 2 * radius, 2 * radius);
+}
diff --git a/examples/opengl/overpainting/bubble.h b/examples/opengl/overpainting/bubble.h
new file mode 100644
index 0000000000..025e92bc00
--- /dev/null
+++ b/examples/opengl/overpainting/bubble.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BUBBLE_H
+#define BUBBLE_H
+
+#include <QBrush>
+#include <QColor>
+#include <QPointF>
+#include <QRect>
+#include <QRectF>
+
+QT_BEGIN_NAMESPACE
+class QPainter;
+QT_END_NAMESPACE
+
+class Bubble
+{
+public:
+ Bubble(const QPointF &position, qreal radius, const QPointF &velocity);
+
+ void drawBubble(QPainter *painter);
+ void updateBrush();
+ void move(const QRect &bbox);
+ QRectF rect();
+
+private:
+ QColor randomColor();
+
+ QBrush brush;
+ QPointF position;
+ QPointF vel;
+ qreal radius;
+ QColor innerColor;
+ QColor outerColor;
+};
+
+#endif
diff --git a/examples/opengl/overpainting/glwidget.cpp b/examples/opengl/overpainting/glwidget.cpp
new file mode 100644
index 0000000000..ded7bf1cf5
--- /dev/null
+++ b/examples/opengl/overpainting/glwidget.cpp
@@ -0,0 +1,283 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+#include <stdlib.h>
+
+#include <math.h>
+
+#include "bubble.h"
+#include "qtlogo.h"
+#include "glwidget.h"
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+//! [0]
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ QTime midnight(0, 0, 0);
+ qsrand(midnight.secsTo(QTime::currentTime()));
+
+ logo = 0;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+
+ qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
+ qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
+
+ animationTimer.setSingleShot(false);
+ connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
+ animationTimer.start(25);
+
+ setAutoFillBackground(false);
+ setMinimumSize(200, 200);
+ setWindowTitle(tr("Overpainting a Scene"));
+}
+//! [0]
+
+//! [1]
+GLWidget::~GLWidget()
+{
+}
+//! [1]
+
+static void qNormalizeAngle(int &angle)
+{
+ while (angle < 0)
+ angle += 360 * 16;
+ while (angle > 360 * 16)
+ angle -= 360 * 16;
+}
+
+void GLWidget::setXRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != xRot)
+ xRot = angle;
+}
+
+void GLWidget::setYRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != yRot)
+ yRot = angle;
+}
+
+void GLWidget::setZRotation(int angle)
+{
+ qNormalizeAngle(angle);
+ if (angle != zRot)
+ zRot = angle;
+}
+
+//! [2]
+void GLWidget::initializeGL()
+{
+ glEnable(GL_MULTISAMPLE);
+
+ logo = new QtLogo(this);
+ logo->setColor(qtGreen.dark());
+}
+//! [2]
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - lastPos.x();
+ int dy = event->y() - lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ setXRotation(xRot + 8 * dy);
+ setYRotation(yRot + 8 * dx);
+ } else if (event->buttons() & Qt::RightButton) {
+ setXRotation(xRot + 8 * dy);
+ setZRotation(zRot + 8 * dx);
+ }
+ lastPos = event->pos();
+}
+
+void GLWidget::paintEvent(QPaintEvent *event)
+{
+ makeCurrent();
+//! [4]
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+//! [4]
+
+//! [6]
+ qglClearColor(qtPurple.dark());
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_MULTISAMPLE);
+ static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
+
+ setupViewport(width(), height());
+//! [6]
+
+//! [7]
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -10.0);
+ glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
+ glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
+ glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
+
+ logo->draw();
+//! [7]
+
+//! [8]
+ glShadeModel(GL_FLAT);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_LIGHTING);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+//! [8]
+
+//! [10]
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ foreach (Bubble *bubble, bubbles) {
+ if (bubble->rect().intersects(event->rect()))
+ bubble->drawBubble(&painter);
+ }
+ drawInstructions(&painter);
+ painter.end();
+}
+//! [10]
+
+//! [11]
+void GLWidget::resizeGL(int width, int height)
+{
+ setupViewport(width, height);
+}
+//! [11]
+
+//! [12]
+void GLWidget::showEvent(QShowEvent *event)
+{
+ Q_UNUSED(event);
+ createBubbles(20 - bubbles.count());
+}
+//! [12]
+
+QSize GLWidget::sizeHint() const
+{
+ return QSize(400, 400);
+}
+
+void GLWidget::createBubbles(int number)
+{
+ for (int i = 0; i < number; ++i) {
+ QPointF position(width()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))),
+ height()*(0.1 + (0.8*qrand()/(RAND_MAX+1.0))));
+ qreal radius = qMin(width(), height())*(0.0125 + 0.0875*qrand()/(RAND_MAX+1.0));
+ QPointF velocity(width()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0)),
+ height()*0.0125*(-0.5 + qrand()/(RAND_MAX+1.0)));
+
+ bubbles.append(new Bubble(position, radius, velocity));
+ }
+}
+
+//! [13]
+void GLWidget::animate()
+{
+ QMutableListIterator<Bubble*> iter(bubbles);
+
+ while (iter.hasNext()) {
+ Bubble *bubble = iter.next();
+ bubble->move(rect());
+ }
+ update();
+}
+//! [13]
+
+//! [14]
+void GLWidget::setupViewport(int width, int height)
+{
+ int side = qMin(width, height);
+ glViewport((width - side) / 2, (height - side) / 2, side, side);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef QT_OPENGL_ES
+ glOrthof(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
+#else
+ glOrtho(-0.5, +0.5, -0.5, 0.5, 4.0, 15.0);
+#endif
+ glMatrixMode(GL_MODELVIEW);
+}
+//! [14]
+
+//! [15]
+void GLWidget::drawInstructions(QPainter *painter)
+{
+ QString text = tr("Click and drag with the left mouse button "
+ "to rotate the Qt logo.");
+ QFontMetrics metrics = QFontMetrics(font());
+ int border = qMax(4, metrics.leading());
+
+ QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125),
+ Qt::AlignCenter | Qt::TextWordWrap, text);
+ painter->setRenderHint(QPainter::TextAntialiasing);
+ painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
+ QColor(0, 0, 0, 127));
+ painter->setPen(Qt::white);
+ painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border),
+ QColor(0, 0, 0, 127));
+ painter->drawText((width() - rect.width())/2, border,
+ rect.width(), rect.height(),
+ Qt::AlignCenter | Qt::TextWordWrap, text);
+}
+//! [15]
diff --git a/examples/opengl/overpainting/glwidget.h b/examples/opengl/overpainting/glwidget.h
new file mode 100644
index 0000000000..178fdf7fe5
--- /dev/null
+++ b/examples/opengl/overpainting/glwidget.h
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QBrush>
+#include <QFont>
+#include <QImage>
+#include <QPen>
+#include <QGLWidget>
+#include <QTimer>
+
+class Bubble;
+class QtLogo;
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+class QWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+//! [0]
+
+ QSize sizeHint() const;
+ int xRotation() const { return xRot; }
+ int yRotation() const { return yRot; }
+ int zRotation() const { return zRot; }
+
+public slots:
+ void setXRotation(int angle);
+ void setYRotation(int angle);
+ void setZRotation(int angle);
+
+//! [1]
+protected:
+ void initializeGL();
+ void paintEvent(QPaintEvent *event);
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void showEvent(QShowEvent *event);
+
+private slots:
+ void animate();
+
+private:
+ void createBubbles(int number);
+ void drawInstructions(QPainter *painter);
+//! [1]
+ void setupViewport(int width, int height);
+
+ QColor qtGreen;
+ QColor qtPurple;
+
+ GLuint object;
+ int xRot;
+ int yRot;
+ int zRot;
+ QPoint lastPos;
+//! [4]
+ QtLogo *logo;
+ QList<Bubble*> bubbles;
+ QTimer animationTimer;
+//! [4]
+};
+
+#endif
diff --git a/examples/opengl/overpainting/main.cpp b/examples/opengl/overpainting/main.cpp
new file mode 100644
index 0000000000..fd9b206b69
--- /dev/null
+++ b/examples/opengl/overpainting/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "glwidget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ GLWidget window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/opengl/overpainting/overpainting.pro b/examples/opengl/overpainting/overpainting.pro
new file mode 100644
index 0000000000..741199d210
--- /dev/null
+++ b/examples/opengl/overpainting/overpainting.pro
@@ -0,0 +1,23 @@
+VPATH += ../shared
+INCLUDEPATH += ../shared
+
+QT += opengl
+HEADERS = bubble.h \
+ glwidget.h \
+ qtlogo.h
+SOURCES = bubble.cpp \
+ glwidget.cpp \
+ main.cpp \
+ qtlogo.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/overpainting
+sources.files = $$SOURCES \
+ $$HEADERS \
+ $$RESOURCES \
+ $$FORMS \
+ overpainting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/overpainting
+INSTALLS += target \
+ sources
+symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/pbuffers/cube.cpp b/examples/opengl/pbuffers/cube.cpp
new file mode 100644
index 0000000000..631595a2d7
--- /dev/null
+++ b/examples/opengl/pbuffers/cube.cpp
@@ -0,0 +1,348 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "cube.h"
+#include "glwidget.h"
+
+#include <QtGui/QImage>
+#include <QtCore/QPropertyAnimation>
+
+static const qreal FACE_SIZE = 0.4;
+
+static const qreal speeds[] = { 3.8f, 4.4f, 5.6f };
+static const qreal amplitudes[] = { 2.0f, 2.5f, 3.0f };
+
+static inline void qSetColor(float colorVec[], QColor c)
+{
+ colorVec[0] = c.redF();
+ colorVec[1] = c.greenF();
+ colorVec[2] = c.blueF();
+ colorVec[3] = c.alphaF();
+}
+
+int Geometry::append(const QVector3D &a, const QVector3D &n, const QVector2D &t)
+{
+ int v = vertices.count();
+ vertices.append(a);
+ normals.append(n);
+ texCoords.append(t);
+ faces.append(v);
+ colors.append(QVector4D(0.6f, 0.6f, 0.6f, 1.0f));
+ return v;
+}
+
+void Geometry::addQuad(const QVector3D &a, const QVector3D &b,
+ const QVector3D &c, const QVector3D &d,
+ const QVector<QVector2D> &tex)
+{
+ QVector3D norm = QVector3D::normal(a, b, c);
+ // append first triangle
+ int aref = append(a, norm, tex[0]);
+ append(b, norm, tex[1]);
+ int cref = append(c, norm, tex[2]);
+ // append second triangle
+ faces.append(aref);
+ faces.append(cref);
+ append(d, norm, tex[3]);
+}
+
+void Geometry::loadArrays() const
+{
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
+ glNormalPointer(GL_FLOAT, 0, normals.constData());
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
+ glColorPointer(4, GL_FLOAT, 0, colors.constData());
+}
+
+void Geometry::setColors(int start, GLfloat colorArray[4][4])
+{
+ int off = faces[start];
+ for (int i = 0; i < 4; ++i)
+ colors[i + off] = QVector4D(colorArray[i][0],
+ colorArray[i][1],
+ colorArray[i][2],
+ colorArray[i][3]);
+}
+
+Tile::Tile(const QVector3D &loc)
+ : location(loc)
+ , start(0)
+ , count(0)
+ , useFlatColor(false)
+ , geom(0)
+{
+ qSetColor(faceColor, QColor(Qt::darkGray));
+}
+
+void Tile::setColors(GLfloat colorArray[4][4])
+{
+ useFlatColor = true;
+ geom->setColors(start, colorArray);
+}
+
+static inline void qMultMatrix(const QMatrix4x4 &mat)
+{
+ if (sizeof(qreal) == sizeof(GLfloat))
+ glMultMatrixf((GLfloat*)mat.constData());
+#ifndef QT_OPENGL_ES
+ else if (sizeof(qreal) == sizeof(GLdouble))
+ glMultMatrixd((GLdouble*)mat.constData());
+#endif
+ else
+ {
+ GLfloat fmat[16];
+ qreal const *r = mat.constData();
+ for (int i = 0; i < 16; ++i)
+ fmat[i] = r[i];
+ glMultMatrixf(fmat);
+ }
+}
+
+void Tile::draw() const
+{
+ QMatrix4x4 mat;
+ mat.translate(location);
+ mat.rotate(orientation);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ qMultMatrix(mat);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
+ glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, geom->indices() + start);
+ glPopMatrix();
+}
+
+TileBuilder::TileBuilder(Geometry *g, qreal depth, qreal size)
+ : verts(4)
+ , tex(4)
+ , start(g->count())
+ , count(0)
+ , geom(g)
+{
+ // front face - make a square with bottom-left at origin
+ verts[br].setX(size);
+ verts[tr].setX(size);
+ verts[tr].setY(size);
+ verts[tl].setY(size);
+
+ // these vert numbers are good for the tex-coords
+ for (int i = 0; i < 4; ++i)
+ tex[i] = verts[i].toVector2D();
+
+ // now move verts half cube width across so cube is centered on origin
+ for (int i = 0; i < 4; ++i)
+ verts[i] -= QVector3D(size / 2.0f, size / 2.0f, -depth);
+
+ // add the front face
+ g->addQuad(verts[bl], verts[br], verts[tr], verts[tl], tex);
+
+ count = g->count() - start;
+}
+
+void TileBuilder::initialize(Tile *tile) const
+{
+ tile->start = start;
+ tile->count = count;
+ tile->geom = geom;
+ qSetColor(tile->faceColor, color);
+}
+
+Tile *TileBuilder::newTile(const QVector3D &loc) const
+{
+ Tile *tile = new Tile(loc);
+ initialize(tile);
+ return tile;
+}
+
+Cube::Cube(const QVector3D &loc)
+ : Tile(loc)
+ , rot(0.0f)
+ , r(0)
+ , animGroup(0)
+{
+}
+
+Cube::~Cube()
+{
+}
+
+void Cube::setAltitude(qreal a)
+{
+ if (location.y() != a)
+ {
+ location.setY(a);
+ emit changed();
+ }
+}
+
+void Cube::setRange(qreal r)
+{
+ if (location.x() != r)
+ {
+ location.setX(r);
+ emit changed();
+ }
+}
+
+void Cube::setRotation(qreal r)
+{
+ if (r != rot)
+ {
+ orientation = QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 1.0f, 1.0f), r);
+ emit changed();
+ }
+}
+
+void Cube::removeBounce()
+{
+ delete animGroup;
+ animGroup = 0;
+ delete r;
+ r = 0;
+}
+
+void Cube::startAnimation()
+{
+ if (r)
+ {
+ r->start();
+ r->setCurrentTime(startx);
+ }
+ if (animGroup)
+ animGroup->start();
+ if (rtn)
+ rtn->start();
+}
+
+void Cube::setAnimationPaused(bool paused)
+{
+ if (paused)
+ {
+ if (r)
+ r->pause();
+ if (animGroup)
+ animGroup->pause();
+ if (rtn)
+ rtn->pause();
+ }
+ else
+ {
+ if (r)
+ r->resume();
+ if (animGroup)
+ animGroup->resume();
+ if (rtn)
+ rtn->resume();
+ }
+}
+
+CubeBuilder::CubeBuilder(Geometry *g, qreal depth, qreal size)
+ : TileBuilder(g, depth)
+ , ix(0)
+{
+ for (int i = 0; i < 4; ++i)
+ verts[i].setZ(size / 2.0f);
+ // back face - "extrude" verts down
+ QVector<QVector3D> back(verts);
+ for (int i = 0; i < 4; ++i)
+ back[i].setZ(-size / 2.0f);
+
+ // add the back face
+ g->addQuad(back[br], back[bl], back[tl], back[tr], tex);
+
+ // add the sides
+ g->addQuad(back[bl], back[br], verts[br], verts[bl], tex);
+ g->addQuad(back[br], back[tr], verts[tr], verts[br], tex);
+ g->addQuad(back[tr], back[tl], verts[tl], verts[tr], tex);
+ g->addQuad(back[tl], back[bl], verts[bl], verts[tl], tex);
+
+ count = g->count() - start;
+}
+
+Cube *CubeBuilder::newCube(const QVector3D &loc) const
+{
+ Cube *c = new Cube(loc);
+ initialize(c);
+ qreal d = 4000.0f;
+ qreal d3 = d / 3.0f;
+ // Animate movement from left to right
+ c->r = new QPropertyAnimation(c, "range");
+ c->r->setStartValue(-1.3f);
+ c->r->setEndValue(1.3f);
+ c->startx = ix * d3 * 3.0f;
+ c->r->setDuration(d * 4.0f);
+ c->r->setLoopCount(-1);
+ c->r->setEasingCurve(QEasingCurve(QEasingCurve::CosineCurve));
+
+ c->animGroup = new QSequentialAnimationGroup(c);
+
+ // Animate movement from bottom to top
+ QPropertyAnimation *a_up = new QPropertyAnimation(c, "altitude", c->animGroup);
+ a_up->setEndValue(loc.y());
+ a_up->setStartValue(loc.y() + amplitudes[ix]);
+ a_up->setDuration(d / speeds[ix]);
+ a_up->setLoopCount(1);
+ a_up->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
+
+ // Animate movement from top to bottom
+ QPropertyAnimation *a_down = new QPropertyAnimation(c, "altitude", c->animGroup);
+ a_down->setEndValue(loc.y() + amplitudes[ix]);
+ a_down->setStartValue(loc.y());
+ a_down->setDuration(d / speeds[ix]);
+ a_down->setLoopCount(1);
+ a_down->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad));
+
+ c->animGroup->addAnimation(a_up);
+ c->animGroup->addAnimation(a_down);
+ c->animGroup->setLoopCount(-1);
+
+ // Animate rotation
+ c->rtn = new QPropertyAnimation(c, "rotation");
+ c->rtn->setStartValue(c->rot);
+ c->rtn->setEndValue(359.0f);
+ c->rtn->setDuration(d * 2.0f);
+ c->rtn->setLoopCount(-1);
+ c->rtn->setDuration(d / 2);
+ ix = (ix + 1) % 3;
+ return c;
+}
diff --git a/examples/opengl/pbuffers/cube.h b/examples/opengl/pbuffers/cube.h
new file mode 100644
index 0000000000..5c985a3782
--- /dev/null
+++ b/examples/opengl/pbuffers/cube.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUBE_H
+#define CUBE_H
+
+#include <QtOpenGL/qgl.h>
+#include <QtCore/qvector.h>
+#include <QtCore/qsequentialanimationgroup.h>
+#include <QtGui/qmatrix4x4.h>
+#include <QtGui/qvector3d.h>
+#include <QtGui/qvector2d.h>
+
+QT_BEGIN_NAMESPACE
+class QPropertyAnimation;
+QT_END_NAMESPACE
+
+class Geometry
+{
+public:
+ void loadArrays() const;
+ void addQuad(const QVector3D &a, const QVector3D &b,
+ const QVector3D &c, const QVector3D &d,
+ const QVector<QVector2D> &tex);
+ void setColors(int start, GLfloat colors[4][4]);
+ const GLushort *indices() const { return faces.constData(); }
+ int count() const { return faces.count(); }
+private:
+ QVector<GLushort> faces;
+ QVector<QVector3D> vertices;
+ QVector<QVector3D> normals;
+ QVector<QVector2D> texCoords;
+ QVector<QVector4D> colors;
+ int append(const QVector3D &a, const QVector3D &n, const QVector2D &t);
+ void addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n);
+ friend class Tile;
+};
+
+class Tile
+{
+public:
+ void draw() const;
+ void setColors(GLfloat[4][4]);
+protected:
+ Tile(const QVector3D &loc = QVector3D());
+ QVector3D location;
+ QQuaternion orientation;
+private:
+ int start;
+ int count;
+ bool useFlatColor;
+ GLfloat faceColor[4];
+ Geometry *geom;
+ friend class TileBuilder;
+};
+
+class TileBuilder
+{
+public:
+ enum { bl, br, tr, tl };
+ TileBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
+ Tile *newTile(const QVector3D &loc = QVector3D()) const;
+ void setColor(QColor c) { color = c; }
+protected:
+ void initialize(Tile *) const;
+ QVector<QVector3D> verts;
+ QVector<QVector2D> tex;
+ int start;
+ int count;
+ Geometry *geom;
+ QColor color;
+};
+
+class Cube : public QObject, public Tile
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal range READ range WRITE setRange)
+ Q_PROPERTY(qreal altitude READ altitude WRITE setAltitude)
+ Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)
+public:
+ Cube(const QVector3D &loc = QVector3D());
+ ~Cube();
+ qreal range() { return location.x(); }
+ void setRange(qreal r);
+ qreal altitude() { return location.y(); }
+ void setAltitude(qreal a);
+ qreal rotation() { return rot; }
+ void setRotation(qreal r);
+ void removeBounce();
+ void startAnimation();
+ void setAnimationPaused(bool paused);
+signals:
+ void changed();
+private:
+ qreal rot;
+ QPropertyAnimation *r;
+ QPropertyAnimation *rtn;
+ QSequentialAnimationGroup *animGroup;
+ qreal startx;
+ friend class CubeBuilder;
+};
+
+class CubeBuilder : public TileBuilder
+{
+public:
+ CubeBuilder(Geometry *, qreal depth = 0.0f, qreal size = 1.0f);
+ Cube *newCube(const QVector3D &loc = QVector3D()) const;
+private:
+ mutable int ix;
+};
+
+#endif // CUBE_H
diff --git a/examples/opengl/pbuffers/cubelogo.png b/examples/opengl/pbuffers/cubelogo.png
new file mode 100644
index 0000000000..3ae0f9ba3f
--- /dev/null
+++ b/examples/opengl/pbuffers/cubelogo.png
Binary files differ
diff --git a/examples/opengl/pbuffers/glwidget.cpp b/examples/opengl/pbuffers/glwidget.cpp
new file mode 100644
index 0000000000..f6f89e5a0e
--- /dev/null
+++ b/examples/opengl/pbuffers/glwidget.cpp
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <math.h>
+
+#include "cube.h"
+
+#include <QGLPixelBuffer>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+static GLfloat colorArray[][4] = {
+ {0.243f, 0.423f, 0.125f, 1.0f},
+ {0.176f, 0.31f, 0.09f, 1.0f},
+ {0.4f, 0.69f, 0.212f, 1.0f},
+ {0.317f, 0.553f, 0.161f, 1.0f}
+};
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+ , geom(0)
+ , cube(0)
+{
+ // create the pbuffer
+ QGLFormat pbufferFormat = format();
+ pbufferFormat.setSampleBuffers(false);
+ pbuffer = new QGLPixelBuffer(QSize(512, 512), pbufferFormat, this);
+ setWindowTitle(tr("OpenGL pbuffers"));
+ initializeGeometry();
+}
+
+GLWidget::~GLWidget()
+{
+ pbuffer->releaseFromDynamicTexture();
+ glDeleteTextures(1, &dynamicTexture);
+ delete pbuffer;
+
+ qDeleteAll(cubes);
+ qDeleteAll(tiles);
+ delete cube;
+}
+
+void GLWidget::initializeGL()
+{
+ initCommon();
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
+ initPbuffer();
+ cube->startAnimation();
+ connect(cube, SIGNAL(changed()), this, SLOT(update()));
+ for (int i = 0; i < 3; ++i)
+ {
+ cubes[i]->startAnimation();
+ connect(cubes[i], SIGNAL(changed()), this, SLOT(update()));
+ }
+}
+
+void GLWidget::paintGL()
+{
+ pbuffer->makeCurrent();
+ drawPbuffer();
+ // On direct render platforms, drawing onto the pbuffer context above
+ // automatically updates the dynamic texture. For cases where rendering
+ // directly to a texture is not supported, explicitly copy.
+ if (!hasDynamicTextureUpdate)
+ pbuffer->updateDynamicTexture(dynamicTexture);
+ makeCurrent();
+
+ // Use the pbuffer as a texture to render the scene
+ glBindTexture(GL_TEXTURE_2D, dynamicTexture);
+
+ // set up to render the scene
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, -10.0f);
+
+ // draw the background
+ glPushMatrix();
+ glScalef(aspect, 1.0f, 1.0f);
+ for (int i = 0; i < tiles.count(); ++i)
+ tiles[i]->draw();
+ glPopMatrix();
+
+ // draw the bouncing cubes
+ for (int i = 0; i < cubes.count(); ++i)
+ cubes[i]->draw();
+}
+
+void GLWidget::initializeGeometry()
+{
+ geom = new Geometry();
+ CubeBuilder cBuilder(geom, 0.5);
+ cBuilder.setColor(QColor(255, 255, 255, 212));
+ // build the 3 bouncing, spinning cubes
+ for (int i = 3; i > 0; --i)
+ cubes.append(cBuilder.newCube(QVector3D((float)(i-1), -1.5f, 5 - i)));
+
+ // build the spinning cube which goes in the dynamic texture
+ cube = cBuilder.newCube();
+ cube->removeBounce();
+
+ // build the background tiles
+ TileBuilder tBuilder(geom);
+ tBuilder.setColor(QColor(Qt::white));
+ for (int c = -2; c <= +2; ++c)
+ for (int r = -2; r <= +2; ++r)
+ tiles.append(tBuilder.newTile(QVector3D(c, r, 0)));
+
+ // graded backdrop for the pbuffer scene
+ TileBuilder bBuilder(geom, 0.0f, 2.0f);
+ bBuilder.setColor(QColor(102, 176, 54, 210));
+ backdrop = bBuilder.newTile(QVector3D(0.0f, 0.0f, -1.5f));
+ backdrop->setColors(colorArray);
+}
+
+void GLWidget::initCommon()
+{
+ qglClearColor(QColor(Qt::darkGray));
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_MULTISAMPLE);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glEnable(GL_TEXTURE_2D);
+
+ geom->loadArrays();
+}
+
+void GLWidget::perspectiveProjection()
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef QT_OPENGL_ES
+ glFrustumf(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
+#else
+ glFrustum(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
+#endif
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void GLWidget::orthographicProjection()
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifdef QT_OPENGL_ES
+ glOrthof(-1.0, +1.0, -1.0, +1.0, -90.0, +90.0);
+#else
+ glOrtho(-1.0, +1.0, -1.0, +1.0, -90.0, +90.0);
+#endif
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void GLWidget::resizeGL(int width, int height)
+{
+ glViewport(0, 0, width, height);
+ aspect = (qreal)width / (qreal)(height ? height : 1);
+ perspectiveProjection();
+}
+
+void GLWidget::drawPbuffer()
+{
+ orthographicProjection();
+
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glDisable(GL_TEXTURE_2D);
+ backdrop->draw();
+ glEnable(GL_TEXTURE_2D);
+
+ glBindTexture(GL_TEXTURE_2D, cubeTexture);
+ glDisable(GL_CULL_FACE);
+ cube->draw();
+ glEnable(GL_CULL_FACE);
+
+ glFlush();
+}
+
+void GLWidget::initPbuffer()
+{
+ pbuffer->makeCurrent();
+
+ cubeTexture = bindTexture(QImage(":res/cubelogo.png"));
+
+ initCommon();
+
+ // generate a texture that has the same size/format as the pbuffer
+ dynamicTexture = pbuffer->generateDynamicTexture();
+
+ // bind the dynamic texture to the pbuffer - this is a no-op under X11
+ hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
+ makeCurrent();
+}
+
+void GLWidget::setAnimationPaused(bool enable)
+{
+ cube->setAnimationPaused(enable);
+ for (int i = 0; i < 3; ++i)
+ cubes[i]->setAnimationPaused(enable);
+}
diff --git a/examples/opengl/pbuffers/glwidget.h b/examples/opengl/pbuffers/glwidget.h
new file mode 100644
index 0000000000..7a8244f4f9
--- /dev/null
+++ b/examples/opengl/pbuffers/glwidget.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QGLWidget>
+
+class Geometry;
+class Cube;
+class Tile;
+QT_BEGIN_NAMESPACE
+class QGLPixelBuffer;
+QT_END_NAMESPACE
+
+class GLWidget : public QGLWidget
+{
+public:
+ GLWidget(QWidget *parent = 0);
+ ~GLWidget();
+
+protected:
+ void initializeGL();
+ void paintGL();
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *) { setAnimationPaused(true); }
+ void mouseReleaseEvent(QMouseEvent *) { setAnimationPaused(false); }
+
+private:
+ void initializeGeometry();
+ void initPbuffer();
+ void initCommon();
+ void perspectiveProjection();
+ void orthographicProjection();
+ void drawPbuffer();
+ void setAnimationPaused(bool enable);
+
+ qreal aspect;
+ GLuint dynamicTexture;
+ GLuint cubeTexture;
+ bool hasDynamicTextureUpdate;
+ QGLPixelBuffer *pbuffer;
+ Geometry *geom;
+ Cube *cube;
+ Tile *backdrop;
+ QList<Cube *> cubes;
+ QList<Tile *> tiles;
+
+};
+//! [3]
+
+#endif
diff --git a/examples/opengl/pbuffers/main.cpp b/examples/opengl/pbuffers/main.cpp
new file mode 100644
index 0000000000..b4f1512cfe
--- /dev/null
+++ b/examples/opengl/pbuffers/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include <QtOpenGL/QGLPixelBuffer>
+
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(pbuffers);
+
+ QApplication a(argc, argv);
+ if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
+ QMessageBox::information(0, "OpenGL pbuffers",
+ "This system does not support OpenGL/pbuffers.");
+ return -1;
+ }
+
+ GLWidget widget(0);
+ widget.resize(640, 480);
+ widget.show();
+ return a.exec();
+}
+
diff --git a/examples/opengl/pbuffers/pbuffers.pro b/examples/opengl/pbuffers/pbuffers.pro
new file mode 100644
index 0000000000..48797ab142
--- /dev/null
+++ b/examples/opengl/pbuffers/pbuffers.pro
@@ -0,0 +1,19 @@
+HEADERS += glwidget.h \
+ cube.h
+SOURCES += glwidget.cpp \
+ main.cpp \
+ cube.cpp
+RESOURCES += pbuffers.qrc
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/pbuffers
+sources.files = $$SOURCES \
+ $$HEADERS \
+ $$RESOURCES \
+ pbuffers.pro \
+ *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/pbuffers
+INSTALLS += target \
+ sources
+symbian:include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/pbuffers/pbuffers.qrc b/examples/opengl/pbuffers/pbuffers.qrc
new file mode 100644
index 0000000000..9fc1a56a1a
--- /dev/null
+++ b/examples/opengl/pbuffers/pbuffers.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>cubelogo.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/pbuffers2/bubbles.svg b/examples/opengl/pbuffers2/bubbles.svg
new file mode 100644
index 0000000000..51730124a2
--- /dev/null
+++ b/examples/opengl/pbuffers2/bubbles.svg
@@ -0,0 +1,215 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg width="20cm" height="15cm" viewBox="0 0 800 600"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink/"
+ baseProfile="tiny" version="1.2">
+ <title>Spheres</title>
+ <desc>Semi-transparent bubbles on a colored background.</desc>
+ <defs>
+ <!-- Create radial gradients for each bubble. -->
+ <radialGradient id="blueBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdcdff" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#cdaacd" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="redBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffcdcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbb99" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="greenBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#cdffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#99aaaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="yellowBubble" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" stop-opacity="1" />
+ <stop offset="25%" stop-color="#ffffcd" stop-opacity=".65" />
+ <stop offset="100%" stop-color="#bbbbaa" stop-opacity=".75" />
+ </radialGradient>
+ <radialGradient id="background" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="400" fx="250" fy="250">
+ <stop offset="0%" stop-color="#ffffee" />
+ <stop offset="100%" stop-color="#ccccaa" />
+ </radialGradient>
+ <linearGradient id="surface" gradientUnits="userSpaceOnUse"
+ x1="-100" y1="200" x2="400" y2="200">
+ <stop offset="0%" stop-color="#ffffcc" />
+ <stop offset="100%" stop-color="#bbbb88" />
+ </linearGradient>
+
+ <!-- Create radial gradients for each circle to make them look like
+ spheres. -->
+ <radialGradient id="blueSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="blue" />
+ <stop offset="100%" stop-color="#222244" />
+ </radialGradient>
+ <radialGradient id="redSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="red" />
+ <stop offset="100%" stop-color="#442222" />
+ </radialGradient>
+ <radialGradient id="greenSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="green" />
+ <stop offset="100%" stop-color="#113311" />
+ </radialGradient>
+ <radialGradient id="yellowSphere" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="-50">
+ <stop offset="0%" stop-color="white" />
+ <stop offset="75%" stop-color="yellow" />
+ <stop offset="100%" stop-color="#444422" />
+ </radialGradient>
+ <radialGradient id="shadowGrad" gradientUnits="userSpaceOnUse"
+ cx="0" cy="0" r="100" fx="-50" fy="50">
+ <stop offset="0%" stop-color="black" stop-opacity="1.0" />
+ <stop offset="100%" stop-color="black" stop-opacity="0.0" />
+ </radialGradient>
+
+ <!-- Define a shadow for each sphere. -->
+ <circle id="shadow" fill="url(#shadowGrad)" cx="0" cy="0" r="100" />
+ <g id="bubble">
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <circle cx="0" cy="0" r="100" />
+ </g>
+ </defs>
+ <g>
+ <rect fill="url(#background)" x="0" y="0" width="800" height="600" />
+ </g>
+
+ <g transform="translate(200,700)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(315,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(80,700)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(255,700)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(565,700)">
+ <g transform="scale(0.4,0.4)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="4s" dur="8s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(715,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="4s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(645,700)">
+ <g transform="scale(0.375,0.375)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="0s" dur="11s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(555,700)">
+ <g transform="scale(0.9,0.9)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="7.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(360,700)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#bubble" fill="url(#blueBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="3s" dur="6s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(215,700)">
+ <g transform="scale(0.45,0.45)">
+ <use xlink:href="#bubble" fill="url(#redBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="5.5s" dur="7s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(420,700)">
+ <g transform="scale(0.75,0.75)">
+ <use xlink:href="#bubble" fill="url(#greenBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="1s" dur="9s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(815,700)">
+ <g transform="scale(0.6,0.6)">
+ <use xlink:href="#bubble" fill="url(#yellowBubble)" />
+ </g>
+ <animateTransform attributeName="transform" type="translate" additive="sum"
+ values="0,0; 0,-800" begin="2s" dur="9.5s" fill="freeze" repeatCount="indefinite" />
+ </g>
+
+ <g transform="translate(225,375)" >
+ <g transform="scale(1.0,0.5)" >
+ <path d="M 0 0 L 350 0 L 450 450 L -100 450 z"
+ fill="url(#surface)" stroke="none" />
+ </g>
+ </g>
+ <g transform="translate(200,0)" >
+ <g transform="translate(200,490) scale(2.0,1.0) rotate(45)" >
+ <rect fill="#a6ce39" x="-69" y="-69" width="138" height="138" />
+ <circle fill="black" cx="0" cy="0" r="50" />
+ <circle fill="#a6ce39" cx="0" cy="0" r="33" />
+ <path fill="black" d="M 37,50 L 50,37 L 12,-1 L 22,-11 L 10,-24 L -24,10
+ L -11,22 L -1,12 Z" />
+ <animateTransform attributeName="transform" type="rotate" additive="sum" values="0; 360"
+ begin="0s" dur="10s" fill="freeze" repeatCount="indefinite" />
+ </g>
+ <g transform="translate(200,375)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#blueSphere)" cx="0" cy="0" r="100" />
+ </g>
+ <g transform="translate(315,440)">
+ <g transform="scale(0.5,0.5)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#redSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(80,475)">
+ <g transform="scale(0.65,0.65)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#greenSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ <g transform="translate(255,525)">
+ <g transform="scale(0.3,0.3)">
+ <use xlink:href="#shadow" transform="translate(25,55) scale(1.0,0.5)" />
+ <circle fill="url(#yellowSphere)" cx="0" cy="0" r="100" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/examples/opengl/pbuffers2/designer.png b/examples/opengl/pbuffers2/designer.png
new file mode 100644
index 0000000000..4f32d57496
--- /dev/null
+++ b/examples/opengl/pbuffers2/designer.png
Binary files differ
diff --git a/examples/opengl/pbuffers2/glwidget.cpp b/examples/opengl/pbuffers2/glwidget.cpp
new file mode 100644
index 0000000000..53b1c5f95b
--- /dev/null
+++ b/examples/opengl/pbuffers2/glwidget.cpp
@@ -0,0 +1,327 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QImage>
+#include "glwidget.h"
+
+#include <math.h>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ setWindowTitle(tr("OpenGL pbuffers 2"));
+
+ pbuffer = new QGLPixelBuffer(1024, 1024, format(), this);
+
+ rot_x = rot_y = rot_z = 0.0f;
+ scale = 0.1f;
+ anim = new QTimeLine(750, this);
+ anim->setUpdateInterval(20);
+ connect(anim, SIGNAL(valueChanged(qreal)), SLOT(animate(qreal)));
+ connect(anim, SIGNAL(finished()), SLOT(animFinished()));
+
+ svg_renderer = new QSvgRenderer(QLatin1String(":/res/bubbles.svg"), this);
+ connect(svg_renderer, SIGNAL(repaintNeeded()), this, SLOT(draw()));
+
+ logo = QImage(":/res/designer.png");
+ logo = logo.convertToFormat(QImage::Format_ARGB32);
+
+ makeCurrent(); // need a current context to create the display list
+ tile_list = glGenLists(1);
+ glNewList(tile_list, GL_COMPILE);
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
+
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
+}
+ glEnd();
+ glEndList();
+
+ wave = new GLfloat[logo.width()*logo.height()];
+ memset(wave, 0, logo.width()*logo.height());
+ startTimer(30); // wave timer
+
+ pbuffer->makeCurrent();
+ dynamicTexture = pbuffer->generateDynamicTexture();
+
+ // bind the dynamic texture to the pbuffer - this is a no-op under X11
+ hasDynamicTextureUpdate = pbuffer->bindToDynamicTexture(dynamicTexture);
+}
+
+GLWidget::~GLWidget()
+{
+ delete[] wave;
+ glDeleteLists(tile_list, 1);
+ pbuffer->releaseFromDynamicTexture();
+ glDeleteTextures(1, &dynamicTexture);
+ delete pbuffer;
+}
+
+void GLWidget::paintEvent(QPaintEvent *)
+{
+ draw();
+}
+
+void GLWidget::draw()
+{
+ QPainter p(this); // used for text overlay
+
+ // save the GL state set for QPainter
+ p.beginNativePainting();
+ saveGLState();
+
+ // render the 'bubbles.svg' file into our pbuffer
+ QPainter pbuffer_painter(pbuffer);
+ svg_renderer->render(&pbuffer_painter);
+ pbuffer_painter.end();
+ glFlush();
+
+ // rendering directly to a texture is not supported on X11 and
+ // some Windows implementations, unfortunately
+ if (!hasDynamicTextureUpdate)
+ pbuffer->updateDynamicTexture(dynamicTexture);
+
+ makeCurrent();
+ // draw into the GL widget
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1, 1, -1, 1, 10, 100);
+ glTranslatef(0.0f, 0.0f, -15.0f);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glViewport(0, 0, width(), height());
+
+ glBindTexture(GL_TEXTURE_2D, dynamicTexture);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_MULTISAMPLE);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ // draw background
+ glPushMatrix();
+ glScalef(1.7f, 1.7f, 1.7f);
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ glCallList(tile_list);
+ glPopMatrix();
+
+ const int w = logo.width();
+ const int h = logo.height();
+
+ glRotatef(rot_x, 1.0f, 0.0f, 0.0f);
+ glRotatef(rot_y, 0.0f, 1.0f, 0.0f);
+ glRotatef(rot_z, 0.0f, 0.0f, 1.0f);
+ glScalef(scale/w, scale/w, scale/w);
+
+ glDepthFunc(GL_LESS);
+ glEnable(GL_DEPTH_TEST);
+
+ // draw the Qt icon
+ glTranslatef(-w+1, -h+1, 0.0f);
+ for (int y=h-1; y>=0; --y) {
+ uint *p = (uint*) logo.scanLine(y);
+ uint *end = p + w;
+ int x = 0;
+ while (p < end) {
+ glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9));
+ glTranslatef(0.0f, 0.0f, wave[y*w+x]);
+ if (qAlpha(*p) > 128)
+ glCallList(tile_list);
+ glTranslatef(0.0f, 0.0f, -wave[y*w+x]);
+ glTranslatef(2.0f, 0.0f, 0.0f);
+ ++x;
+ ++p;
+ }
+ glTranslatef(-w*2.0f, 2.0f, 0.0f);
+ }
+
+ // restore the GL state that QPainter expects
+ restoreGLState();
+ p.endNativePainting();
+
+ // draw the overlayed text using QPainter
+ p.setPen(QColor(197, 197, 197, 157));
+ p.setBrush(QColor(197, 197, 197, 127));
+ p.drawRect(QRect(0, 0, width(), 50));
+ p.setPen(Qt::black);
+ p.setBrush(Qt::NoBrush);
+ const QString str1(tr("A simple OpenGL pbuffer example."));
+ const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip."));
+ QFontMetrics fm(p.font());
+ p.drawText(width()/2 - fm.width(str1)/2, 20, str1);
+ p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2);
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *e)
+{
+ anchor = e->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *e)
+{
+ QPoint diff = e->pos() - anchor;
+ if (e->buttons() & Qt::LeftButton) {
+ rot_x += diff.y()/5.0f;
+ rot_y += diff.x()/5.0f;
+ } else if (e->buttons() & Qt::RightButton) {
+ rot_z += diff.x()/5.0f;
+ }
+
+ anchor = e->pos();
+ draw();
+}
+
+void GLWidget::wheelEvent(QWheelEvent *e)
+{
+ e->delta() > 0 ? scale += scale*0.1f : scale -= scale*0.1f;
+ draw();
+}
+
+void GLWidget::mouseDoubleClickEvent(QMouseEvent *)
+{
+ anim->start();
+}
+
+void GLWidget::animate(qreal val)
+{
+ rot_y = val * 180;
+ draw();
+}
+
+void GLWidget::animFinished()
+{
+ if (anim->direction() == QTimeLine::Forward)
+ anim->setDirection(QTimeLine::Backward);
+ else
+ anim->setDirection(QTimeLine::Forward);
+}
+
+void GLWidget::saveGLState()
+{
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+}
+
+void GLWidget::restoreGLState()
+{
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ glPopAttrib();
+}
+
+#define PI 3.14159
+
+void GLWidget::timerEvent(QTimerEvent *)
+{
+ if (QApplication::mouseButtons() != 0)
+ return;
+
+ static bool scale_in = true;
+
+ if (scale_in && scale > 35.0f)
+ scale_in = false;
+ else if (!scale_in && scale < .5f)
+ scale_in = true;
+
+ scale = scale_in ? scale + scale*0.01f : scale-scale*0.01f;
+ rot_z += 0.3f;
+ rot_x += 0.1f;
+
+ int dx, dy; // disturbance point
+ float s, v, W, t;
+ int i, j;
+ static float wt[128][128];
+ const int width = logo.width();
+ const int AMP = 5;
+
+ dx = dy = width >> 1;
+
+ W = .3f;
+ v = -4; // wave speed
+
+ for (i = 0; i < width; ++i) {
+ for ( j = 0; j < width; ++j) {
+ s = sqrt((double) ((j - dx) * (j - dx) + (i - dy) * (i - dy)));
+ wt[i][j] += 0.1f;
+ t = s / v;
+ if (s != 0)
+ wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t)) / (0.2*(s + 2));
+ else
+ wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t));
+ }
+ }
+}
diff --git a/examples/opengl/pbuffers2/glwidget.h b/examples/opengl/pbuffers2/glwidget.h
new file mode 100644
index 0000000000..515d5b44fc
--- /dev/null
+++ b/examples/opengl/pbuffers2/glwidget.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtOpenGL>
+#include <QImage>
+#include <QTimeLine>
+#include <QSvgRenderer>
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent);
+ ~GLWidget();
+
+ void saveGLState();
+ void restoreGLState();
+
+ void paintEvent(QPaintEvent *);
+ void mousePressEvent(QMouseEvent *);
+ void mouseDoubleClickEvent(QMouseEvent *);
+ void mouseMoveEvent(QMouseEvent *);
+ void timerEvent(QTimerEvent *);
+ void wheelEvent(QWheelEvent *);
+
+public slots:
+ void animate(qreal);
+ void animFinished();
+ void draw();
+
+private:
+ QPoint anchor;
+ float scale;
+ float rot_x, rot_y, rot_z;
+ GLuint tile_list;
+ GLfloat *wave;
+ bool hasDynamicTextureUpdate;
+
+ QImage logo;
+ QTimeLine *anim;
+ QSvgRenderer *svg_renderer;
+
+ GLuint dynamicTexture;
+ QGLPixelBuffer *pbuffer;
+};
+
diff --git a/examples/opengl/pbuffers2/main.cpp b/examples/opengl/pbuffers2/main.cpp
new file mode 100644
index 0000000000..0abe0b9faa
--- /dev/null
+++ b/examples/opengl/pbuffers2/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(pbuffers2);
+
+ QApplication a(argc, argv);
+ if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
+ QMessageBox::information(0, "OpenGL pbuffers 2",
+ "This system does not support OpenGL/pbuffers.");
+ return -1;
+ }
+
+ GLWidget widget(0);
+ widget.resize(640, 480);
+ widget.show();
+ return a.exec();
+}
+
diff --git a/examples/opengl/pbuffers2/pbuffers2.pro b/examples/opengl/pbuffers2/pbuffers2.pro
new file mode 100644
index 0000000000..ea1f6bd293
--- /dev/null
+++ b/examples/opengl/pbuffers2/pbuffers2.pro
@@ -0,0 +1,23 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Fri May 12 17:15:46 2006
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT += opengl svg
+
+# Input
+HEADERS += glwidget.h
+SOURCES += glwidget.cpp main.cpp
+RESOURCES += pbuffers2.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/pbuffers2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES pbuffers2.pro *.png *.svg
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/pbuffers2
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/pbuffers2/pbuffers2.qrc b/examples/opengl/pbuffers2/pbuffers2.qrc
new file mode 100644
index 0000000000..986f1ca385
--- /dev/null
+++ b/examples/opengl/pbuffers2/pbuffers2.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/res">
+ <file>bubbles.svg</file>
+ <file>designer.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/samplebuffers/glwidget.cpp b/examples/opengl/samplebuffers/glwidget.cpp
new file mode 100644
index 0000000000..537dbd9bba
--- /dev/null
+++ b/examples/opengl/samplebuffers/glwidget.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "glwidget.h"
+#include <math.h>
+
+#ifndef GL_MULTISAMPLE
+#define GL_MULTISAMPLE 0x809D
+#endif
+
+GLWidget::GLWidget(QWidget *parent)
+ : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
+{
+ startTimer(40);
+ setWindowTitle(tr("Sample Buffers"));
+}
+
+void GLWidget::initializeGL()
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-.5, .5, .5, -.5, -1000, 1000);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+
+ makeObject();
+}
+
+void GLWidget::resizeGL(int w, int h)
+{
+ glViewport(0, 0, w, h);
+}
+
+void GLWidget::paintGL()
+{
+ static float rot = 0.0;
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glEnable(GL_MULTISAMPLE);
+ glTranslatef(-0.25f, -0.10f, 0.0f);
+ glScalef(0.75f, 1.15f, 0.0f);
+ glRotatef(rot, 0.0f, 0.f, 1.0f);
+ glCallList(list);
+ glPopMatrix();
+
+ glPushMatrix();
+ glDisable(GL_MULTISAMPLE);
+ glTranslatef(0.25f, -0.10f, 0.0f);
+ glScalef(0.75f, 1.15f, 0.0f);
+ glRotatef(rot, 0.0f, 0.0f, 1.0f);
+ glCallList(list);
+ glPopMatrix();
+
+ rot += 0.2f;
+
+ qglColor(Qt::black);
+ renderText(-0.35, 0.4, 0.0, "Multisampling enabled");
+ renderText(0.15, 0.4, 0.0, "Multisampling disabled");
+}
+
+void GLWidget::timerEvent(QTimerEvent *)
+{
+ update();
+}
+
+void GLWidget::makeObject()
+{
+ QColor qtGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0));
+ const double Pi = 3.14159265358979323846;
+ const int NumSectors = 15;
+ GLdouble x1 = +0.06;
+ GLdouble y1 = -0.14;
+ GLdouble x2 = +0.14;
+ GLdouble y2 = -0.06;
+ GLdouble x3 = +0.08;
+ GLdouble y3 = +0.00;
+ GLdouble x4 = +0.30;
+ GLdouble y4 = +0.22;
+
+ list = glGenLists(1);
+ glNewList(list, GL_COMPILE);
+ {
+ for (int i = 0; i < NumSectors; ++i) {
+ double angle1 = (i * 2 * Pi) / NumSectors;
+ GLdouble x5 = 0.30 * sin(angle1);
+ GLdouble y5 = 0.30 * cos(angle1);
+ GLdouble x6 = 0.20 * sin(angle1);
+ GLdouble y6 = 0.20 * cos(angle1);
+
+ double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
+ GLdouble x7 = 0.20 * sin(angle2);
+ GLdouble y7 = 0.20 * cos(angle2);
+ GLdouble x8 = 0.30 * sin(angle2);
+ GLdouble y8 = 0.30 * cos(angle2);
+
+ qglColor(qtGreen);
+ quad(GL_QUADS, x5, y5, x6, y6, x7, y7, x8, y8);
+ qglColor(Qt::black);
+ quad(GL_LINE_LOOP, x5, y5, x6, y6, x7, y7, x8, y8);
+ }
+
+ qglColor(qtGreen);
+ quad(GL_QUADS, x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(GL_QUADS, x3, y3, x4, y4, y4, x4, y3, x3);
+
+ qglColor(Qt::black);
+ quad(GL_LINE_LOOP, x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(GL_LINE_LOOP, x3, y3, x4, y4, y4, x4, y3, x3);
+ }
+ glEndList();
+}
+
+void GLWidget::quad(GLenum primitive, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
+{
+ glBegin(primitive);
+ {
+ glVertex2d(x1, y1);
+ glVertex2d(x2, y2);
+ glVertex2d(x3, y3);
+ glVertex2d(x4, y4);
+ }
+ glEnd();
+}
diff --git a/examples/opengl/samplebuffers/glwidget.h b/examples/opengl/samplebuffers/glwidget.h
new file mode 100644
index 0000000000..1d9b7b54a1
--- /dev/null
+++ b/examples/opengl/samplebuffers/glwidget.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtOpenGL>
+
+class GLWidget : public QGLWidget
+{
+public:
+ GLWidget(QWidget *parent);
+
+protected:
+ void initializeGL();
+ void resizeGL(int w, int h);
+ void paintGL();
+ void timerEvent(QTimerEvent *);
+
+ void makeObject();
+ void quad(GLenum primitive, GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
+ GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);
+
+private:
+ GLuint list;
+};
+
diff --git a/examples/opengl/samplebuffers/main.cpp b/examples/opengl/samplebuffers/main.cpp
new file mode 100644
index 0000000000..8d4df924dd
--- /dev/null
+++ b/examples/opengl/samplebuffers/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QMessageBox>
+#include "glwidget.h"
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+
+ QGLFormat f = QGLFormat::defaultFormat();
+ f.setSampleBuffers(true);
+ QGLFormat::setDefaultFormat(f);
+ if (!QGLFormat::hasOpenGL()) {
+ QMessageBox::information(0, "OpenGL samplebuffers",
+ "This system does not support OpenGL.");
+ return 0;
+ }
+
+ GLWidget widget(0);
+
+ if (!widget.format().sampleBuffers()) {
+ QMessageBox::information(0, "OpenGL samplebuffers",
+ "This system does not have sample buffer support.");
+ return 0;
+ }
+
+ widget.resize(640, 480);
+ widget.show();
+
+ return a.exec();
+}
+
diff --git a/examples/opengl/samplebuffers/samplebuffers.pro b/examples/opengl/samplebuffers/samplebuffers.pro
new file mode 100644
index 0000000000..c284318524
--- /dev/null
+++ b/examples/opengl/samplebuffers/samplebuffers.pro
@@ -0,0 +1,12 @@
+HEADERS += glwidget.h
+SOURCES += glwidget.cpp main.cpp
+
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/samplebuffers
+sources.files = $$SOURCES $$HEADERS samplebuffers.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/samplebuffers
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/shared/qtlogo.cpp b/examples/opengl/shared/qtlogo.cpp
new file mode 100644
index 0000000000..93b92809e0
--- /dev/null
+++ b/examples/opengl/shared/qtlogo.cpp
@@ -0,0 +1,411 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGLWidget>
+#include <QMatrix4x4>
+#include <QVector3D>
+
+#include <qmath.h>
+
+#include "qtlogo.h"
+
+static const qreal tee_height = 0.311126;
+static const qreal cross_width = 0.25;
+static const qreal bar_thickness = 0.113137;
+static const qreal inside_diam = 0.20;
+static const qreal outside_diam = 0.30;
+static const qreal logo_depth = 0.10;
+static const int num_divisions = 32;
+
+//! [0]
+struct Geometry
+{
+ QVector<GLushort> faces;
+ QVector<QVector3D> vertices;
+ QVector<QVector3D> normals;
+ void appendSmooth(const QVector3D &a, const QVector3D &n, int from);
+ void appendFaceted(const QVector3D &a, const QVector3D &n);
+ void finalize();
+ void loadArrays() const;
+};
+//! [0]
+
+//! [1]
+class Patch
+{
+public:
+ enum Smoothing { Faceted, Smooth };
+ Patch(Geometry *);
+ void setSmoothing(Smoothing s) { sm = s; }
+ void translate(const QVector3D &t);
+ void rotate(qreal deg, QVector3D axis);
+ void draw() const;
+ void addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n);
+ void addQuad(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d);
+
+ GLushort start;
+ GLushort count;
+ GLushort initv;
+
+ GLfloat faceColor[4];
+ QMatrix4x4 mat;
+ Smoothing sm;
+ Geometry *geom;
+};
+//! [1]
+
+static inline void qSetColor(float colorVec[], QColor c)
+{
+ colorVec[0] = c.redF();
+ colorVec[1] = c.greenF();
+ colorVec[2] = c.blueF();
+ colorVec[3] = c.alphaF();
+}
+
+void Geometry::loadArrays() const
+{
+ glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
+ glNormalPointer(GL_FLOAT, 0, normals.constData());
+}
+
+void Geometry::finalize()
+{
+ // TODO: add vertex buffer uploading here
+
+ // Finish smoothing normals by ensuring accumulated normals are returned
+ // to length 1.0.
+ for (int i = 0; i < normals.count(); ++i)
+ normals[i].normalize();
+}
+
+void Geometry::appendSmooth(const QVector3D &a, const QVector3D &n, int from)
+{
+ // Smooth normals are acheived by averaging the normals for faces meeting
+ // at a point. First find the point in geometry already generated
+ // (working backwards, since most often the points shared are between faces
+ // recently added).
+ int v = vertices.count() - 1;
+ for ( ; v >= from; --v)
+ if (qFuzzyCompare(vertices[v], a))
+ break;
+ if (v < from)
+ {
+ // The vert was not found so add it as a new one, and initialize
+ // its corresponding normal
+ v = vertices.count();
+ vertices.append(a);
+ normals.append(n);
+ }
+ else
+ {
+ // Vert found, accumulate normals into corresponding normal slot.
+ // Must call finalize once finished accumulating normals
+ normals[v] += n;
+ }
+ // In both cases (found or not) reference the vert via its index
+ faces.append(v);
+}
+
+void Geometry::appendFaceted(const QVector3D &a, const QVector3D &n)
+{
+ // Faceted normals are achieved by duplicating the vert for every
+ // normal, so that faces meeting at a vert get a sharp edge.
+ int v = vertices.count();
+ vertices.append(a);
+ normals.append(n);
+ faces.append(v);
+}
+
+Patch::Patch(Geometry *g)
+ : start(g->faces.count())
+ , count(0)
+ , initv(g->vertices.count())
+ , sm(Patch::Smooth)
+ , geom(g)
+{
+ qSetColor(faceColor, QColor(Qt::darkGray));
+}
+
+void Patch::rotate(qreal deg, QVector3D axis)
+{
+ mat.rotate(deg, axis);
+}
+
+void Patch::translate(const QVector3D &t)
+{
+ mat.translate(t);
+}
+
+static inline void qMultMatrix(const QMatrix4x4 &mat)
+{
+ if (sizeof(qreal) == sizeof(GLfloat))
+ glMultMatrixf((GLfloat*)mat.constData());
+#ifndef QT_OPENGL_ES
+ else if (sizeof(qreal) == sizeof(GLdouble))
+ glMultMatrixd((GLdouble*)mat.constData());
+#endif
+ else
+ {
+ GLfloat fmat[16];
+ qreal const *r = mat.constData();
+ for (int i = 0; i < 16; ++i)
+ fmat[i] = r[i];
+ glMultMatrixf(fmat);
+ }
+}
+
+//! [2]
+void Patch::draw() const
+{
+ glPushMatrix();
+ qMultMatrix(mat);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);
+
+ const GLushort *indices = geom->faces.constData();
+ glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices + start);
+ glPopMatrix();
+}
+//! [2]
+
+void Patch::addTri(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n)
+{
+ QVector3D norm = n.isNull() ? QVector3D::normal(a, b, c) : n;
+ if (sm == Smooth)
+ {
+ geom->appendSmooth(a, norm, initv);
+ geom->appendSmooth(b, norm, initv);
+ geom->appendSmooth(c, norm, initv);
+ }
+ else
+ {
+ geom->appendFaceted(a, norm);
+ geom->appendFaceted(b, norm);
+ geom->appendFaceted(c, norm);
+ }
+ count += 3;
+}
+
+void Patch::addQuad(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d)
+{
+ QVector3D norm = QVector3D::normal(a, b, c);
+ if (sm == Smooth)
+ {
+ addTri(a, b, c, norm);
+ addTri(a, c, d, norm);
+ }
+ else
+ {
+ // If faceted share the two common verts
+ addTri(a, b, c, norm);
+ int k = geom->vertices.count();
+ geom->appendSmooth(a, norm, k);
+ geom->appendSmooth(c, norm, k);
+ geom->appendFaceted(d, norm);
+ count += 3;
+ }
+}
+
+static inline QVector<QVector3D> extrude(const QVector<QVector3D> &verts, qreal depth)
+{
+ QVector<QVector3D> extr = verts;
+ for (int v = 0; v < extr.count(); ++v)
+ extr[v].setZ(extr[v].z() - depth);
+ return extr;
+}
+
+class Rectoid
+{
+public:
+ void translate(const QVector3D &t)
+ {
+ for (int i = 0; i < parts.count(); ++i)
+ parts[i]->translate(t);
+ }
+ void rotate(qreal deg, QVector3D axis)
+ {
+ for (int i = 0; i < parts.count(); ++i)
+ parts[i]->rotate(deg, axis);
+ }
+
+ // No special Rectoid destructor - the parts are fetched out of this member
+ // variable, and destroyed by the new owner
+ QList<Patch*> parts;
+};
+
+class RectPrism : public Rectoid
+{
+public:
+ RectPrism(Geometry *g, qreal width, qreal height, qreal depth);
+};
+
+RectPrism::RectPrism(Geometry *g, qreal width, qreal height, qreal depth)
+{
+ enum { bl, br, tr, tl };
+ Patch *fb = new Patch(g);
+ fb->setSmoothing(Patch::Faceted);
+
+ // front face
+ QVector<QVector3D> r(4);
+ r[br].setX(width);
+ r[tr].setX(width);
+ r[tr].setY(height);
+ r[tl].setY(height);
+ QVector3D adjToCenter(-width / 2.0, -height / 2.0, depth / 2.0);
+ for (int i = 0; i < 4; ++i)
+ r[i] += adjToCenter;
+ fb->addQuad(r[bl], r[br], r[tr], r[tl]);
+
+ // back face
+ QVector<QVector3D> s = extrude(r, depth);
+ fb->addQuad(s[tl], s[tr], s[br], s[bl]);
+
+ // side faces
+ Patch *sides = new Patch(g);
+ sides->setSmoothing(Patch::Faceted);
+ sides->addQuad(s[bl], s[br], r[br], r[bl]);
+ sides->addQuad(s[br], s[tr], r[tr], r[br]);
+ sides->addQuad(s[tr], s[tl], r[tl], r[tr]);
+ sides->addQuad(s[tl], s[bl], r[bl], r[tl]);
+
+ parts << fb << sides;
+}
+
+class RectTorus : public Rectoid
+{
+public:
+ RectTorus(Geometry *g, qreal iRad, qreal oRad, qreal depth, int numSectors);
+};
+
+RectTorus::RectTorus(Geometry *g, qreal iRad, qreal oRad, qreal depth, int k)
+{
+ QVector<QVector3D> inside;
+ QVector<QVector3D> outside;
+ for (int i = 0; i < k; ++i) {
+ qreal angle = (i * 2 * M_PI) / k;
+ inside << QVector3D(iRad * qSin(angle), iRad * qCos(angle), depth / 2.0);
+ outside << QVector3D(oRad * qSin(angle), oRad * qCos(angle), depth / 2.0);
+ }
+ inside << QVector3D(0.0, iRad, 0.0);
+ outside << QVector3D(0.0, oRad, 0.0);
+ QVector<QVector3D> in_back = extrude(inside, depth);
+ QVector<QVector3D> out_back = extrude(outside, depth);
+
+ // Create front, back and sides as separate patches so that smooth normals
+ // are generated for the curving sides, but a faceted edge is created between
+ // sides and front/back
+ Patch *front = new Patch(g);
+ for (int i = 0; i < k; ++i)
+ front->addQuad(outside[i], inside[i],
+ inside[(i + 1) % k], outside[(i + 1) % k]);
+ Patch *back = new Patch(g);
+ for (int i = 0; i < k; ++i)
+ back->addQuad(in_back[i], out_back[i],
+ out_back[(i + 1) % k], in_back[(i + 1) % k]);
+ Patch *is = new Patch(g);
+ for (int i = 0; i < k; ++i)
+ is->addQuad(in_back[i], in_back[(i + 1) % k],
+ inside[(i + 1) % k], inside[i]);
+ Patch *os = new Patch(g);
+ for (int i = 0; i < k; ++i)
+ os->addQuad(out_back[(i + 1) % k], out_back[i],
+ outside[i], outside[(i + 1) % k]);
+ parts << front << back << is << os;
+}
+
+QtLogo::QtLogo(QObject *parent, int divisions, qreal scale)
+ : QObject(parent)
+ , geom(new Geometry())
+{
+ buildGeometry(divisions, scale);
+}
+
+QtLogo::~QtLogo()
+{
+ qDeleteAll(parts);
+ delete geom;
+}
+
+void QtLogo::setColor(QColor c)
+{
+ for (int i = 0; i < parts.count(); ++i)
+ qSetColor(parts[i]->faceColor, c);
+}
+
+//! [3]
+void QtLogo::buildGeometry(int divisions, qreal scale)
+{
+ qreal cw = cross_width * scale;
+ qreal bt = bar_thickness * scale;
+ qreal ld = logo_depth * scale;
+ qreal th = tee_height *scale;
+
+ RectPrism cross(geom, cw, bt, ld);
+ RectPrism stem(geom, bt, th, ld);
+
+ QVector3D z(0.0, 0.0, 1.0);
+ cross.rotate(45.0, z);
+ stem.rotate(45.0, z);
+
+ qreal stem_downshift = (th + bt) / 2.0;
+ stem.translate(QVector3D(0.0, -stem_downshift, 0.0));
+
+ RectTorus body(geom, 0.20, 0.30, 0.1, divisions);
+
+ parts << stem.parts << cross.parts << body.parts;
+
+ geom->finalize();
+}
+//! [3]
+
+//! [4]
+void QtLogo::draw() const
+{
+ geom->loadArrays();
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_NORMAL_ARRAY);
+
+ for (int i = 0; i < parts.count(); ++i)
+ parts[i]->draw();
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+}
+//! [4]
diff --git a/examples/opengl/shared/qtlogo.h b/examples/opengl/shared/qtlogo.h
new file mode 100644
index 0000000000..4c16ec1c4e
--- /dev/null
+++ b/examples/opengl/shared/qtlogo.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTLOGO_H
+#define QTLOGO_H
+
+#include <QObject>
+#include <QColor>
+
+class Patch;
+struct Geometry;
+
+//! [0]
+class QtLogo : public QObject
+{
+public:
+ QtLogo(QObject *parent, int d = 64, qreal s = 1.0);
+ ~QtLogo();
+ void setColor(QColor c);
+ void draw() const;
+private:
+ void buildGeometry(int d, qreal s);
+
+ QList<Patch *> parts;
+ Geometry *geom;
+};
+//! [0]
+
+#endif // QTLOGO_H
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
new file mode 100644
index 0000000000..b5374c0200
--- /dev/null
+++ b/examples/opengl/textures/glwidget.cpp
@@ -0,0 +1,245 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtOpenGL>
+
+#include "glwidget.h"
+
+GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget)
+ : QGLWidget(parent, shareWidget)
+{
+ clearColor = Qt::black;
+ xRot = 0;
+ yRot = 0;
+ zRot = 0;
+#ifdef QT_OPENGL_ES_2
+ program = 0;
+#endif
+}
+
+GLWidget::~GLWidget()
+{
+}
+
+QSize GLWidget::minimumSizeHint() const
+{
+ return QSize(50, 50);
+}
+
+QSize GLWidget::sizeHint() const
+{
+ return QSize(200, 200);
+}
+
+void GLWidget::rotateBy(int xAngle, int yAngle, int zAngle)
+{
+ xRot += xAngle;
+ yRot += yAngle;
+ zRot += zAngle;
+ updateGL();
+}
+
+void GLWidget::setClearColor(const QColor &color)
+{
+ clearColor = color;
+ updateGL();
+}
+
+void GLWidget::initializeGL()
+{
+ makeObject();
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+#ifndef QT_OPENGL_ES_2
+ glEnable(GL_TEXTURE_2D);
+#endif
+
+#ifdef QT_OPENGL_ES_2
+
+#define PROGRAM_VERTEX_ATTRIBUTE 0
+#define PROGRAM_TEXCOORD_ATTRIBUTE 1
+
+ QGLShader *vshader = new QGLShader(QGLShader::Vertex, this);
+ const char *vsrc =
+ "attribute highp vec4 vertex;\n"
+ "attribute mediump vec4 texCoord;\n"
+ "varying mediump vec4 texc;\n"
+ "uniform mediump mat4 matrix;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_Position = matrix * vertex;\n"
+ " texc = texCoord;\n"
+ "}\n";
+ vshader->compileSourceCode(vsrc);
+
+ QGLShader *fshader = new QGLShader(QGLShader::Fragment, this);
+ const char *fsrc =
+ "uniform sampler2D texture;\n"
+ "varying mediump vec4 texc;\n"
+ "void main(void)\n"
+ "{\n"
+ " gl_FragColor = texture2D(texture, texc.st);\n"
+ "}\n";
+ fshader->compileSourceCode(fsrc);
+
+ program = new QGLShaderProgram(this);
+ program->addShader(vshader);
+ program->addShader(fshader);
+ program->bindAttributeLocation("vertex", PROGRAM_VERTEX_ATTRIBUTE);
+ program->bindAttributeLocation("texCoord", PROGRAM_TEXCOORD_ATTRIBUTE);
+ program->link();
+
+ program->bind();
+ program->setUniformValue("texture", 0);
+
+#endif
+}
+
+void GLWidget::paintGL()
+{
+ qglClearColor(clearColor);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+#if !defined(QT_OPENGL_ES_2)
+
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, -10.0f);
+ glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
+ glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
+ glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
+
+ glVertexPointer(3, GL_FLOAT, 0, vertices.constData());
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData());
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+#else
+
+ QMatrix4x4 m;
+ m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f);
+ m.translate(0.0f, 0.0f, -10.0f);
+ m.rotate(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
+ m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
+ m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
+
+ program->setUniformValue("matrix", m);
+ program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE);
+ program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE);
+ program->setAttributeArray
+ (PROGRAM_VERTEX_ATTRIBUTE, vertices.constData());
+ program->setAttributeArray
+ (PROGRAM_TEXCOORD_ATTRIBUTE, texCoords.constData());
+
+#endif
+
+ for (int i = 0; i < 6; ++i) {
+ glBindTexture(GL_TEXTURE_2D, textures[i]);
+ glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
+ }
+}
+
+void GLWidget::resizeGL(int width, int height)
+{
+ int side = qMin(width, height);
+ glViewport((width - side) / 2, (height - side) / 2, side, side);
+
+#if !defined(QT_OPENGL_ES_2)
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+#ifndef QT_OPENGL_ES
+ glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+#else
+ glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
+#endif
+ glMatrixMode(GL_MODELVIEW);
+#endif
+}
+
+void GLWidget::mousePressEvent(QMouseEvent *event)
+{
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ int dx = event->x() - lastPos.x();
+ int dy = event->y() - lastPos.y();
+
+ if (event->buttons() & Qt::LeftButton) {
+ rotateBy(8 * dy, 8 * dx, 0);
+ } else if (event->buttons() & Qt::RightButton) {
+ rotateBy(8 * dy, 0, 8 * dx);
+ }
+ lastPos = event->pos();
+}
+
+void GLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
+{
+ emit clicked();
+}
+
+void GLWidget::makeObject()
+{
+ static const int coords[6][4][3] = {
+ { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
+ { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
+ { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
+ { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
+ { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
+ { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
+ };
+
+ for (int j=0; j < 6; ++j) {
+ textures[j] = bindTexture
+ (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D);
+ }
+
+ for (int i = 0; i < 6; ++i) {
+ for (int j = 0; j < 4; ++j) {
+ texCoords.append
+ (QVector2D(j == 0 || j == 3, j == 0 || j == 1));
+ vertices.append
+ (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1],
+ 0.2 * coords[i][j][2]));
+ }
+ }
+}
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
new file mode 100644
index 0000000000..fd9246bef2
--- /dev/null
+++ b/examples/opengl/textures/glwidget.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <QtGui>
+#include <QGLWidget>
+
+class QGLShaderProgram;
+
+class GLWidget : public QGLWidget
+{
+ Q_OBJECT
+
+public:
+ GLWidget(QWidget *parent = 0, QGLWidget *shareWidget = 0);
+ ~GLWidget();
+
+ QSize minimumSizeHint() const;
+ QSize sizeHint() const;
+ void rotateBy(int xAngle, int yAngle, int zAngle);
+ void setClearColor(const QColor &color);
+
+signals:
+ void clicked();
+
+protected:
+ void initializeGL();
+ void paintGL();
+ void resizeGL(int width, int height);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ void makeObject();
+
+ QColor clearColor;
+ QPoint lastPos;
+ int xRot;
+ int yRot;
+ int zRot;
+ GLuint textures[6];
+ QVector<QVector3D> vertices;
+ QVector<QVector2D> texCoords;
+#ifdef QT_OPENGL_ES_2
+ QGLShaderProgram *program;
+#endif
+};
+
+#endif
diff --git a/examples/opengl/textures/images/side1.png b/examples/opengl/textures/images/side1.png
new file mode 100644
index 0000000000..2e6b471cc5
--- /dev/null
+++ b/examples/opengl/textures/images/side1.png
Binary files differ
diff --git a/examples/opengl/textures/images/side2.png b/examples/opengl/textures/images/side2.png
new file mode 100644
index 0000000000..d1acf1b2a0
--- /dev/null
+++ b/examples/opengl/textures/images/side2.png
Binary files differ
diff --git a/examples/opengl/textures/images/side3.png b/examples/opengl/textures/images/side3.png
new file mode 100644
index 0000000000..a6386131d8
--- /dev/null
+++ b/examples/opengl/textures/images/side3.png
Binary files differ
diff --git a/examples/opengl/textures/images/side4.png b/examples/opengl/textures/images/side4.png
new file mode 100644
index 0000000000..ebbc1e3c34
--- /dev/null
+++ b/examples/opengl/textures/images/side4.png
Binary files differ
diff --git a/examples/opengl/textures/images/side5.png b/examples/opengl/textures/images/side5.png
new file mode 100644
index 0000000000..fa2f709fe7
--- /dev/null
+++ b/examples/opengl/textures/images/side5.png
Binary files differ
diff --git a/examples/opengl/textures/images/side6.png b/examples/opengl/textures/images/side6.png
new file mode 100644
index 0000000000..97141e45eb
--- /dev/null
+++ b/examples/opengl/textures/images/side6.png
Binary files differ
diff --git a/examples/opengl/textures/main.cpp b/examples/opengl/textures/main.cpp
new file mode 100644
index 0000000000..b477e7b05b
--- /dev/null
+++ b/examples/opengl/textures/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(textures);
+
+ QApplication app(argc, argv);
+ Window window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/opengl/textures/textures.pro b/examples/opengl/textures/textures.pro
new file mode 100644
index 0000000000..d2e311bc2d
--- /dev/null
+++ b/examples/opengl/textures/textures.pro
@@ -0,0 +1,15 @@
+HEADERS = glwidget.h \
+ window.h
+SOURCES = glwidget.cpp \
+ main.cpp \
+ window.cpp
+RESOURCES = textures.qrc
+QT += opengl
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/textures
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS textures.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/opengl/textures
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/opengl/textures/textures.qrc b/examples/opengl/textures/textures.qrc
new file mode 100644
index 0000000000..efa9e9c8d2
--- /dev/null
+++ b/examples/opengl/textures/textures.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/side1.png</file>
+ <file>images/side2.png</file>
+ <file>images/side3.png</file>
+ <file>images/side4.png</file>
+ <file>images/side5.png</file>
+ <file>images/side6.png</file>
+</qresource>
+</RCC>
diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp
new file mode 100644
index 0000000000..50f3afecce
--- /dev/null
+++ b/examples/opengl/textures/window.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "glwidget.h"
+#include "window.h"
+
+Window::Window()
+{
+ QGridLayout *mainLayout = new QGridLayout;
+
+ for (int i = 0; i < NumRows; ++i) {
+ for (int j = 0; j < NumColumns; ++j) {
+ QColor clearColor;
+ clearColor.setHsv(((i * NumColumns) + j) * 255
+ / (NumRows * NumColumns - 1),
+ 255, 63);
+
+ glWidgets[i][j] = new GLWidget(0, 0);
+ glWidgets[i][j]->setClearColor(clearColor);
+ glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16);
+ mainLayout->addWidget(glWidgets[i][j], i, j);
+
+ connect(glWidgets[i][j], SIGNAL(clicked()),
+ this, SLOT(setCurrentGlWidget()));
+ }
+ }
+ setLayout(mainLayout);
+
+ currentGlWidget = glWidgets[0][0];
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(rotateOneStep()));
+ timer->start(20);
+
+ setWindowTitle(tr("Textures"));
+}
+
+void Window::setCurrentGlWidget()
+{
+ currentGlWidget = qobject_cast<GLWidget *>(sender());
+}
+
+void Window::rotateOneStep()
+{
+ if (currentGlWidget)
+ currentGlWidget->rotateBy(+2 * 16, +2 * 16, -1 * 16);
+}
diff --git a/examples/opengl/textures/window.h b/examples/opengl/textures/window.h
new file mode 100644
index 0000000000..571fae47bc
--- /dev/null
+++ b/examples/opengl/textures/window.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+class GLWidget;
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void setCurrentGlWidget();
+ void rotateOneStep();
+
+private:
+ enum { NumRows = 2, NumColumns = 3 };
+
+ GLWidget *glWidgets[NumRows][NumColumns];
+ GLWidget *currentGlWidget;
+};
+
+#endif
diff --git a/examples/openvg/README b/examples/openvg/README
new file mode 100644
index 0000000000..5e385ea0ce
--- /dev/null
+++ b/examples/openvg/README
@@ -0,0 +1,40 @@
+Qt provides support for integration with OpenVG implementations on
+platforms with appropriate hardware acceleration.
+
+These examples demonstrate the basic techniques used to take advantage of
+OpenVG in Qt applications. In particular, the "star" example shows how
+to mix QPainter and OpenVG calls in the same paint event.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/openvg/openvg.pro b/examples/openvg/openvg.pro
new file mode 100644
index 0000000000..ffbe81c312
--- /dev/null
+++ b/examples/openvg/openvg.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+SUBDIRS = star
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/openvg
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS openvg.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/openvg
+INSTALLS += target sources
diff --git a/examples/openvg/star/main.cpp b/examples/openvg/star/main.cpp
new file mode 100644
index 0000000000..0f3378e881
--- /dev/null
+++ b/examples/openvg/star/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL 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 <QApplication>
+#include "starwidget.h"
+
+int main(int argc, char *argv[])
+{
+#ifdef Q_OS_SYMBIAN
+ QApplication::setGraphicsSystem("openvg");
+#endif
+ QApplication app(argc, argv);
+ StarWidget mw;
+ mw.show();
+ return app.exec();
+}
diff --git a/examples/openvg/star/star.pro b/examples/openvg/star/star.pro
new file mode 100644
index 0000000000..6ae1238536
--- /dev/null
+++ b/examples/openvg/star/star.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+TARGET = star
+CONFIG += qt debug warn_on
+QT += openvg
+SOURCES = starwidget.cpp main.cpp
+HEADERS = starwidget.h
+LIBS += $$QMAKE_LIBS_OPENVG \ No newline at end of file
diff --git a/examples/openvg/star/starwidget.cpp b/examples/openvg/star/starwidget.cpp
new file mode 100644
index 0000000000..93438edb1e
--- /dev/null
+++ b/examples/openvg/star/starwidget.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL 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 "starwidget.h"
+
+StarWidget::StarWidget(QWidget *parent)
+ : QWidget(parent)
+ , path(VG_INVALID_HANDLE)
+ , pen(Qt::red, 4.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)
+ , brush(Qt::yellow)
+{
+ setMinimumSize(220, 250);
+ setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+}
+
+static VGubyte const starSegments[] = {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_REL,
+ VG_LINE_TO_REL,
+ VG_LINE_TO_REL,
+ VG_LINE_TO_REL,
+ VG_CLOSE_PATH
+};
+static VGfloat const starCoords[] = {
+ 110, 35,
+ 50, 160,
+ -130, -100,
+ 160, 0,
+ -130, 100
+};
+
+void StarWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter;
+ painter.begin(this);
+
+ // Make sure that we are using the OpenVG paint engine.
+ if (painter.paintEngine()->type() != QPaintEngine::OpenVG) {
+#ifdef Q_WS_QWS
+ qWarning("Not using OpenVG: use the '-display' option to specify an OpenVG driver");
+#else
+ qWarning("Not using OpenVG: specify '-graphicssystem OpenVG'");
+#endif
+ return;
+ }
+
+ // Select a pen and a brush for drawing the star.
+ painter.setPen(pen);
+ painter.setBrush(brush);
+
+ // We want the star border to be anti-aliased.
+ painter.setRenderHints(QPainter::Antialiasing);
+
+ // Flush the state changes to the OpenVG implementation
+ // and prepare to perform raw OpenVG calls.
+ painter.beginNativePainting();
+
+ // Cache the path if we haven't already or if the path has
+ // become invalid because the window's context has changed.
+ if (path == VG_INVALID_HANDLE || !vgGetPathCapabilities(path)) {
+ path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+ VG_PATH_DATATYPE_F,
+ 1.0f, // scale
+ 0.0f, // bias
+ 6, // segmentCapacityHint
+ 10, // coordCapacityHint
+ VG_PATH_CAPABILITY_ALL);
+ vgAppendPathData(path, sizeof(starSegments), starSegments, starCoords);
+ }
+
+ // Draw the star directly using the OpenVG API.
+ vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH);
+
+ // Restore normal QPainter operations.
+ painter.endNativePainting();
+
+ painter.end();
+}
diff --git a/examples/openvg/star/starwidget.h b/examples/openvg/star/starwidget.h
new file mode 100644
index 0000000000..70ef5ea1e3
--- /dev/null
+++ b/examples/openvg/star/starwidget.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL 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 STARWIDGET_H
+#define STARWIDGET_H
+
+#include <QWidget>
+#include <QPainter>
+#include <QPaintEngine>
+#include "qvg.h"
+
+class StarWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ StarWidget(QWidget *parent = 0);
+ ~StarWidget() {}
+
+protected:
+ void paintEvent(QPaintEvent *);
+
+private:
+ VGPath path;
+ QPen pen;
+ QBrush brush;
+};
+
+#endif
diff --git a/examples/painting/README b/examples/painting/README
new file mode 100644
index 0000000000..4f9dca0181
--- /dev/null
+++ b/examples/painting/README
@@ -0,0 +1,42 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/painting/basicdrawing/basicdrawing.pro b/examples/painting/basicdrawing/basicdrawing.pro
new file mode 100644
index 0000000000..0e5d3f68b8
--- /dev/null
+++ b/examples/painting/basicdrawing/basicdrawing.pro
@@ -0,0 +1,17 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A649
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/basicdrawing/basicdrawing.qrc b/examples/painting/basicdrawing/basicdrawing.qrc
new file mode 100644
index 0000000000..9d8a23a1c8
--- /dev/null
+++ b/examples/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/painting/basicdrawing/images/brick.png b/examples/painting/basicdrawing/images/brick.png
new file mode 100644
index 0000000000..87e7df5b04
--- /dev/null
+++ b/examples/painting/basicdrawing/images/brick.png
Binary files differ
diff --git a/examples/painting/basicdrawing/images/qt-logo.png b/examples/painting/basicdrawing/images/qt-logo.png
new file mode 100644
index 0000000000..a8b452e07a
--- /dev/null
+++ b/examples/painting/basicdrawing/images/qt-logo.png
Binary files differ
diff --git a/examples/painting/basicdrawing/main.cpp b/examples/painting/basicdrawing/main.cpp
new file mode 100644
index 0000000000..6662742166
--- /dev/null
+++ b/examples/painting/basicdrawing/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/basicdrawing/renderarea.cpp b/examples/painting/basicdrawing/renderarea.cpp
new file mode 100644
index 0000000000..0906159e0e
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.cpp
@@ -0,0 +1,207 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/painting/basicdrawing/renderarea.h b/examples/painting/basicdrawing/renderarea.h
new file mode 100644
index 0000000000..02e9b268f5
--- /dev/null
+++ b/examples/painting/basicdrawing/renderarea.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/basicdrawing/window.cpp b/examples/painting/basicdrawing/window.cpp
new file mode 100644
index 0000000000..54422a0104
--- /dev/null
+++ b/examples/painting/basicdrawing/window.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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 Style:"));
+ brushStyleLabel->setBuddy(brushStyleComboBox);
+//! [4]
+
+//! [5]
+ otherOptionsLabel = new QLabel(tr("Other 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->setRowMinimumHeight(1, 6);
+ mainLayout->addWidget(shapeLabel, 2, 1, Qt::AlignRight);
+ mainLayout->addWidget(shapeComboBox, 2, 2);
+ mainLayout->addWidget(penWidthLabel, 3, 1, Qt::AlignRight);
+ mainLayout->addWidget(penWidthSpinBox, 3, 2);
+ mainLayout->addWidget(penStyleLabel, 4, 1, Qt::AlignRight);
+ mainLayout->addWidget(penStyleComboBox, 4, 2);
+ mainLayout->addWidget(penCapLabel, 5, 1, Qt::AlignRight);
+ mainLayout->addWidget(penCapComboBox, 5, 2);
+ mainLayout->addWidget(penJoinLabel, 6, 1, Qt::AlignRight);
+ mainLayout->addWidget(penJoinComboBox, 6, 2);
+ mainLayout->addWidget(brushStyleLabel, 7, 1, Qt::AlignRight);
+ mainLayout->addWidget(brushStyleComboBox, 7, 2);
+ mainLayout->setRowMinimumHeight(8, 6);
+ mainLayout->addWidget(otherOptionsLabel, 9, 1, Qt::AlignRight);
+ mainLayout->addWidget(antialiasingCheckBox, 9, 2);
+ mainLayout->addWidget(transformationsCheckBox, 10, 2);
+ 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/painting/basicdrawing/window.h b/examples/painting/basicdrawing/window.h
new file mode 100644
index 0000000000..2f939fb741
--- /dev/null
+++ b/examples/painting/basicdrawing/window.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/concentriccircles/circlewidget.cpp b/examples/painting/concentriccircles/circlewidget.cpp
new file mode 100644
index 0000000000..d801710b99
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/painting/concentriccircles/circlewidget.h b/examples/painting/concentriccircles/circlewidget.h
new file mode 100644
index 0000000000..e8f583d643
--- /dev/null
+++ b/examples/painting/concentriccircles/circlewidget.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/concentriccircles/concentriccircles.pro b/examples/painting/concentriccircles/concentriccircles.pro
new file mode 100644
index 0000000000..a47ac18193
--- /dev/null
+++ b/examples/painting/concentriccircles/concentriccircles.pro
@@ -0,0 +1,16 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A64A
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/concentriccircles/main.cpp b/examples/painting/concentriccircles/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/concentriccircles/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/concentriccircles/window.cpp b/examples/painting/concentriccircles/window.cpp
new file mode 100644
index 0000000000..a01333be62
--- /dev/null
+++ b/examples/painting/concentriccircles/window.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/painting/concentriccircles/window.h b/examples/painting/concentriccircles/window.h
new file mode 100644
index 0000000000..b5cc7d9a97
--- /dev/null
+++ b/examples/painting/concentriccircles/window.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/fontsampler/fontsampler.pro b/examples/painting/fontsampler/fontsampler.pro
new file mode 100644
index 0000000000..9d845c413d
--- /dev/null
+++ b/examples/painting/fontsampler/fontsampler.pro
@@ -0,0 +1,12 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/painting/fontsampler/main.cpp b/examples/painting/fontsampler/main.cpp
new file mode 100644
index 0000000000..01c8adae53
--- /dev/null
+++ b/examples/painting/fontsampler/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/fontsampler/mainwindow.cpp b/examples/painting/fontsampler/mainwindow.cpp
new file mode 100644
index 0000000000..0976d1f971
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+}
+
+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();
+}
+
+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;
+}
+
+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();
+}
diff --git a/examples/painting/fontsampler/mainwindow.h b/examples/painting/fontsampler/mainwindow.h
new file mode 100644
index 0000000000..7ea4cd5ed0
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindow.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "ui_mainwindowbase.h"
+
+QT_BEGIN_NAMESPACE
+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();
+ void on_printAction_triggered();
+ void on_printPreviewAction_triggered();
+ void on_unmarkAction_triggered();
+ void printDocument(QPrinter *printer);
+ void printPage(int index, QPainter *painter, QPrinter *printer);
+ 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/painting/fontsampler/mainwindowbase.ui b/examples/painting/fontsampler/mainwindowbase.ui
new file mode 100644
index 0000000000..6545b34083
--- /dev/null
+++ b/examples/painting/fontsampler/mainwindowbase.ui
@@ -0,0 +1,140 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <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="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</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>24</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|QDockWidget::NoDockWidgetFeatures</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="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTreeWidget" name="fontTree" >
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ </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>
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/painting/imagecomposition/imagecomposer.cpp b/examples/painting/imagecomposition/imagecomposer.cpp
new file mode 100644
index 0000000000..a41f405fd0
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.cpp
@@ -0,0 +1,208 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+
+ 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/painting/imagecomposition/imagecomposer.h b/examples/painting/imagecomposition/imagecomposer.h
new file mode 100644
index 0000000000..2248ba3033
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposer.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/imagecomposition/imagecomposition.pro b/examples/painting/imagecomposition/imagecomposition.pro
new file mode 100644
index 0000000000..883d7edc0c
--- /dev/null
+++ b/examples/painting/imagecomposition/imagecomposition.pro
@@ -0,0 +1,15 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A64B
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/imagecomposition/imagecomposition.qrc b/examples/painting/imagecomposition/imagecomposition.qrc
new file mode 100644
index 0000000000..ebba7b2913
--- /dev/null
+++ b/examples/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/painting/imagecomposition/images/background.png b/examples/painting/imagecomposition/images/background.png
new file mode 100644
index 0000000000..f6ad899823
--- /dev/null
+++ b/examples/painting/imagecomposition/images/background.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/blackrectangle.png b/examples/painting/imagecomposition/images/blackrectangle.png
new file mode 100644
index 0000000000..5f2ecf8318
--- /dev/null
+++ b/examples/painting/imagecomposition/images/blackrectangle.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/butterfly.png b/examples/painting/imagecomposition/images/butterfly.png
new file mode 100644
index 0000000000..f3e050eca2
--- /dev/null
+++ b/examples/painting/imagecomposition/images/butterfly.png
Binary files differ
diff --git a/examples/painting/imagecomposition/images/checker.png b/examples/painting/imagecomposition/images/checker.png
new file mode 100644
index 0000000000..546609de3f
--- /dev/null
+++ b/examples/painting/imagecomposition/images/checker.png
Binary files differ
diff --git a/examples/painting/imagecomposition/main.cpp b/examples/painting/imagecomposition/main.cpp
new file mode 100644
index 0000000000..e70fa5fae9
--- /dev/null
+++ b/examples/painting/imagecomposition/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/painterpaths/main.cpp b/examples/painting/painterpaths/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/painterpaths/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/painterpaths/painterpaths.pro b/examples/painting/painterpaths/painterpaths.pro
new file mode 100644
index 0000000000..c61ad897a0
--- /dev/null
+++ b/examples/painting/painterpaths/painterpaths.pro
@@ -0,0 +1,17 @@
+HEADERS = renderarea.h \
+ window.h
+SOURCES = main.cpp \
+ renderarea.cpp \
+ window.cpp
+unix:!mac:!symbian:!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
+
+symbian {
+ TARGET.UID3 = 0xA000A64C
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/painterpaths/renderarea.cpp b/examples/painting/painterpaths/renderarea.cpp
new file mode 100644
index 0000000000..977fe30ed0
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/painting/painterpaths/renderarea.h b/examples/painting/painterpaths/renderarea.h
new file mode 100644
index 0000000000..2c50ecb353
--- /dev/null
+++ b/examples/painting/painterpaths/renderarea.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/painterpaths/window.cpp b/examples/painting/painterpaths/window.cpp
new file mode 100644
index 0000000000..429f470b26
--- /dev/null
+++ b/examples/painting/painterpaths/window.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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[0] = new RenderArea(rectPath);
+ renderAreas[1] = new RenderArea(roundRectPath);
+ renderAreas[2] = new RenderArea(ellipsePath);
+ renderAreas[3] = new RenderArea(piePath);
+ renderAreas[4] = new RenderArea(polygonPath);
+ renderAreas[5] = new RenderArea(groupPath);
+ renderAreas[6] = new RenderArea(textPath);
+ renderAreas[7] = new RenderArea(bezierPath);
+ renderAreas[8] = new RenderArea(starPath);
+ Q_ASSERT(NumRenderAreas == 9);
+//! [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("\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 (int i = 0; i < NumRenderAreas; ++i) {
+ connect(penWidthSpinBox, SIGNAL(valueChanged(int)),
+ renderAreas[i], SLOT(setPenWidth(int)));
+ connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)),
+ renderAreas[i], SLOT(setRotationAngle(int)));
+ }
+
+//! [16] //! [17]
+ QGridLayout *topLayout = new QGridLayout;
+ for (int i = 0; i < NumRenderAreas; ++i)
+ topLayout->addWidget(renderAreas[i], 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 (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->setFillRule(rule);
+}
+//! [19]
+
+//! [20]
+void Window::fillGradientChanged()
+{
+ QColor color1 = qvariant_cast<QColor>(currentItemData(fillColor1ComboBox));
+ QColor color2 = qvariant_cast<QColor>(currentItemData(fillColor2ComboBox));
+
+ for (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->setFillGradient(color1, color2);
+}
+//! [20]
+
+//! [21]
+void Window::penColorChanged()
+{
+ QColor color = qvariant_cast<QColor>(currentItemData(penColorComboBox));
+
+ for (int i = 0; i < NumRenderAreas; ++i)
+ renderAreas[i]->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/painting/painterpaths/window.h b/examples/painting/painterpaths/window.h
new file mode 100644
index 0000000000..4891fdd153
--- /dev/null
+++ b/examples/painting/painterpaths/window.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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]
+ enum { NumRenderAreas = 9 };
+
+ RenderArea *renderAreas[NumRenderAreas];
+ 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/painting/painting.pro b/examples/painting/painting.pro
new file mode 100644
index 0000000000..1885f217cb
--- /dev/null
+++ b/examples/painting/painting.pro
@@ -0,0 +1,18 @@
+TEMPLATE = subdirs
+SUBDIRS = basicdrawing \
+ concentriccircles \
+ imagecomposition \
+ painterpaths \
+ transformations
+
+!wince*:!symbian: SUBDIRS += fontsampler
+
+contains(QT_CONFIG, svg): SUBDIRS += svggenerator svgviewer
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/painting/transformations/main.cpp b/examples/painting/transformations/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/painting/transformations/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/transformations/renderarea.cpp b/examples/painting/transformations/renderarea.cpp
new file mode 100644
index 0000000000..568cfde287
--- /dev/null
+++ b/examples/painting/transformations/renderarea.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/painting/transformations/renderarea.h b/examples/painting/transformations/renderarea.h
new file mode 100644
index 0000000000..039430d9a3
--- /dev/null
+++ b/examples/painting/transformations/renderarea.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/painting/transformations/transformations.pro b/examples/painting/transformations/transformations.pro
new file mode 100644
index 0000000000..9256f1499a
--- /dev/null
+++ b/examples/painting/transformations/transformations.pro
@@ -0,0 +1,16 @@
+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
+
+symbian {
+ TARGET.UID3 = 0xA000A64D
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/painting/transformations/window.cpp b/examples/painting/transformations/window.cpp
new file mode 100644
index 0000000000..fc3bcb856d
--- /dev/null
+++ b/examples/painting/transformations/window.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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\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/painting/transformations/window.h b/examples/painting/transformations/window.h
new file mode 100644
index 0000000000..b7cd575a81
--- /dev/null
+++ b/examples/painting/transformations/window.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/qmake/precompile/main.cpp b/examples/qmake/precompile/main.cpp
new file mode 100644
index 0000000000..033fed35cb
--- /dev/null
+++ b/examples/qmake/precompile/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QApplication>
+#include <QPushButton>
+#include <QLabel>
+#include "myobject.h"
+#include "mydialog.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MyObject obj;
+ MyDialog dialog;
+
+ dialog.connect(dialog.aButton, SIGNAL(clicked()), SLOT(close()));
+ dialog.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/qmake/precompile/mydialog.cpp b/examples/qmake/precompile/mydialog.cpp
new file mode 100644
index 0000000000..96d3fb0313
--- /dev/null
+++ b/examples/qmake/precompile/mydialog.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mydialog.h"
+
+MyDialog::MyDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ setupUi(this);
+}
diff --git a/examples/qmake/precompile/mydialog.h b/examples/qmake/precompile/mydialog.h
new file mode 100644
index 0000000000..5e2a06f923
--- /dev/null
+++ b/examples/qmake/precompile/mydialog.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYDIALOG_H
+#define MYDIALOG_H
+
+#include "ui_mydialog.h"
+
+class MyDialog : public QDialog, public Ui::MyDialog
+{
+ Q_OBJECT
+
+public:
+ MyDialog(QWidget *parent = 0);
+};
+
+#endif
diff --git a/examples/qmake/precompile/mydialog.ui b/examples/qmake/precompile/mydialog.ui
new file mode 100644
index 0000000000..d765b30760
--- /dev/null
+++ b/examples/qmake/precompile/mydialog.ui
@@ -0,0 +1,47 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>MyDialog</class>
+ <widget class="QDialog" name="MyDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>401</width>
+ <height>70</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Mach 2!</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="aLabel" >
+ <property name="text" >
+ <string>Join the life in the fastlane; - PCH enable your project today! -</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="aButton" >
+ <property name="text" >
+ <string>&amp;Quit</string>
+ </property>
+ <property name="shortcut" >
+ <string>Alt+Q</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/qmake/precompile/myobject.cpp b/examples/qmake/precompile/myobject.cpp
new file mode 100644
index 0000000000..3a8cef7991
--- /dev/null
+++ b/examples/qmake/precompile/myobject.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <iostream>
+#include <QDebug>
+#include <QObject>
+#include "myobject.h"
+
+MyObject::MyObject()
+ : QObject()
+{
+ std::cout << "MyObject::MyObject()\n";
+}
+//! [0]
+
+MyObject::~MyObject()
+{
+ qDebug() << "MyObject::~MyObject()";
+}
diff --git a/examples/qmake/precompile/myobject.h b/examples/qmake/precompile/myobject.h
new file mode 100644
index 0000000000..8953832b82
--- /dev/null
+++ b/examples/qmake/precompile/myobject.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYOBJECT_H
+#define MYOBJECT_H
+
+//! [0]
+#include <QObject>
+
+class MyObject : public QObject
+{
+public:
+ MyObject();
+ ~MyObject();
+};
+//! [0]
+
+#endif
diff --git a/examples/qmake/precompile/precompile.pro b/examples/qmake/precompile/precompile.pro
new file mode 100644
index 0000000000..6360f06f07
--- /dev/null
+++ b/examples/qmake/precompile/precompile.pro
@@ -0,0 +1,22 @@
+#############################################
+#
+# Example for using Precompiled Headers
+#
+#############################################
+#! [0]
+TEMPLATE = app
+LANGUAGE = C++
+CONFIG += console precompile_header
+
+# Use Precompiled headers (PCH)
+PRECOMPILED_HEADER = stable.h
+
+HEADERS = stable.h \
+ mydialog.h \
+ myobject.h
+SOURCES = main.cpp \
+ mydialog.cpp \
+ myobject.cpp \
+ util.cpp
+FORMS = mydialog.ui
+#! [0]
diff --git a/examples/qmake/precompile/stable.h b/examples/qmake/precompile/stable.h
new file mode 100644
index 0000000000..140af3c053
--- /dev/null
+++ b/examples/qmake/precompile/stable.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+/* Add C includes here */
+
+#if defined __cplusplus
+/* Add C++ includes here */
+
+# include <iostream>
+# include <QApplication>
+# include <QPushButton>
+# include <QLabel>
+#endif
+//! [0]
diff --git a/examples/qmake/precompile/util.cpp b/examples/qmake/precompile/util.cpp
new file mode 100644
index 0000000000..ba85b14f87
--- /dev/null
+++ b/examples/qmake/precompile/util.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+void util_function_does_nothing()
+{
+ // Nothing here...
+ int x = 0;
+ ++x;
+}
+//! [0]
+
diff --git a/examples/qmake/tutorial/hello.cpp b/examples/qmake/tutorial/hello.cpp
new file mode 100644
index 0000000000..9edb4e349f
--- /dev/null
+++ b/examples/qmake/tutorial/hello.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include "hello.h"
+
+MyPushButton::MyPushButton(const QString &text)
+ : QPushButton(text)
+{
+ setObjectName("mypushbutton");
+ qDebug() << "My PushButton has been constructed";
+}
diff --git a/examples/qmake/tutorial/hello.h b/examples/qmake/tutorial/hello.h
new file mode 100644
index 0000000000..05bdeef036
--- /dev/null
+++ b/examples/qmake/tutorial/hello.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QPushButton>
+
+class MyPushButton : public QPushButton
+{
+public:
+ MyPushButton(const QString &text);
+};
diff --git a/examples/qmake/tutorial/hellounix.cpp b/examples/qmake/tutorial/hellounix.cpp
new file mode 100644
index 0000000000..8594546455
--- /dev/null
+++ b/examples/qmake/tutorial/hellounix.cpp
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// This file does nothing, but check your Makefile to see if there is a
+// reference to hello_win.cpp - there shouldn't be if qmake is used on X11.
diff --git a/examples/qmake/tutorial/hellowin.cpp b/examples/qmake/tutorial/hellowin.cpp
new file mode 100644
index 0000000000..b23d940d96
--- /dev/null
+++ b/examples/qmake/tutorial/hellowin.cpp
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// This file does nothing, but check your Makefile to see if there is a
+// reference to hello_x11.cpp - there shouldn't be if qmake is used on Windows.
diff --git a/examples/qmake/tutorial/main.cpp b/examples/qmake/tutorial/main.cpp
new file mode 100644
index 0000000000..c68602ce22
--- /dev/null
+++ b/examples/qmake/tutorial/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "hello.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MyPushButton helloButton("Hello world!");
+ helloButton.resize(100, 30);
+
+ helloButton.show();
+ return app.exec();
+}
diff --git a/examples/qtconcurrent/README b/examples/qtconcurrent/README
new file mode 100644
index 0000000000..af659af2cc
--- /dev/null
+++ b/examples/qtconcurrent/README
@@ -0,0 +1,38 @@
+Qt 4 extends Qt's support for multithreaded applications with an API for
+concurrent programming which includes implementations of the well-known
+map-reduce and filter-reduce algorithms.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/qtconcurrent/imagescaling/imagescaling.cpp b/examples/qtconcurrent/imagescaling/imagescaling.cpp
new file mode 100644
index 0000000000..6ed7ae7511
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "imagescaling.h"
+#include "math.h"
+
+#ifndef QT_NO_CONCURRENT
+
+const int imageSize = 100;
+
+QImage scale(const QString &imageFileName)
+{
+ QImage image(imageFileName);
+ return image.scaled(QSize(imageSize, imageSize), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+}
+
+Images::Images(QWidget *parent)
+: QWidget(parent)
+{
+ setWindowTitle(tr("Image loading and scaling example"));
+ resize(800, 600);
+
+ imageScaling = new QFutureWatcher<QImage>(this);
+ connect(imageScaling, SIGNAL(resultReadyAt(int)), SLOT(showImage(int)));
+ connect(imageScaling, SIGNAL(finished()), SLOT(finished()));
+
+ openButton = new QPushButton(tr("Open Images"));
+ connect(openButton, SIGNAL(clicked()), SLOT(open()));
+
+ cancelButton = new QPushButton(tr("Cancel"));
+ cancelButton->setEnabled(false);
+ connect(cancelButton, SIGNAL(clicked()), imageScaling, SLOT(cancel()));
+
+ pauseButton = new QPushButton(tr("Pause/Resume"));
+ pauseButton->setEnabled(false);
+ connect(pauseButton, SIGNAL(clicked()), imageScaling, SLOT(togglePaused()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout();
+ buttonLayout->addWidget(openButton);
+ buttonLayout->addWidget(cancelButton);
+ buttonLayout->addWidget(pauseButton);
+ buttonLayout->addStretch();
+
+ imagesLayout = new QGridLayout();
+
+ mainLayout = new QVBoxLayout();
+ mainLayout->addLayout(buttonLayout);
+ mainLayout->addLayout(imagesLayout);
+ mainLayout->addStretch();
+ setLayout(mainLayout);
+}
+
+Images::~Images()
+{
+ imageScaling->cancel();
+ imageScaling->waitForFinished();
+}
+
+void Images::open()
+{
+ // Cancel and wait if we are already loading images.
+ if (imageScaling->isRunning()) {
+ imageScaling->cancel();
+ imageScaling->waitForFinished();
+ }
+
+ // Show a file open dialog at QDesktopServices::PicturesLocation.
+ QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Images"),
+ QDesktopServices::storageLocation(QDesktopServices::PicturesLocation),
+ "*.jpg *.png");
+
+ if (files.count() == 0)
+ return;
+
+ // Do a simple layout.
+ qDeleteAll(labels);
+ labels.clear();
+
+ int dim = sqrt(qreal(files.count())) + 1;
+ for (int i = 0; i < dim; ++i) {
+ for (int j = 0; j < dim; ++j) {
+ QLabel *imageLabel = new QLabel;
+ imageLabel->setFixedSize(imageSize,imageSize);
+ imagesLayout->addWidget(imageLabel,i,j);
+ labels.append(imageLabel);
+ }
+ }
+
+ // Use mapped to run the thread safe scale function on the files.
+ imageScaling->setFuture(QtConcurrent::mapped(files, scale));
+
+ openButton->setEnabled(false);
+ cancelButton->setEnabled(true);
+ pauseButton->setEnabled(true);
+}
+
+void Images::showImage(int num)
+{
+ labels[num]->setPixmap(QPixmap::fromImage(imageScaling->resultAt(num)));
+}
+
+void Images::finished()
+{
+ openButton->setEnabled(true);
+ cancelButton->setEnabled(false);
+ pauseButton->setEnabled(false);
+}
+
+#endif // QT_NO_CONCURRENT
+
diff --git a/examples/qtconcurrent/imagescaling/imagescaling.h b/examples/qtconcurrent/imagescaling/imagescaling.h
new file mode 100644
index 0000000000..096e880b1b
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef IMAGESCALING_H
+#define IMAGESCALING_H
+
+#include <QtGui>
+
+#ifndef QT_NO_CONCURRENT
+
+class Images : public QWidget
+{
+Q_OBJECT
+public:
+ Images(QWidget *parent = 0);
+ ~Images();
+public Q_SLOTS:
+ void open();
+ void showImage(int num);
+ void finished();
+private:
+ QPushButton *openButton;
+ QPushButton *cancelButton;
+ QPushButton *pauseButton;
+ QVBoxLayout *mainLayout;
+ QList<QLabel *> labels;
+ QGridLayout *imagesLayout;
+ QFutureWatcher<QImage> *imageScaling;
+};
+
+#else
+
+// Dummy class required because QT_NO_CONCURRENT is not set when moc is run.
+class Images : public QWidget
+{
+Q_OBJECT
+public Q_SLOTS:
+ void open() {}
+ void showImage(int) {}
+ void finished() {}
+};
+
+#endif // QT_NO_CONCURRENT
+
+#endif // IMAGESCALING_H
diff --git a/examples/qtconcurrent/imagescaling/imagescaling.pro b/examples/qtconcurrent/imagescaling/imagescaling.pro
new file mode 100644
index 0000000000..b9601ad48b
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/imagescaling.pro
@@ -0,0 +1,17 @@
+TEMPLATE = app
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp imagescaling.cpp
+HEADERS += imagescaling.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/imagescaling
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/imagescaling
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: DEPLOYMENT_PLUGIN += qgif qjpeg qtiff
diff --git a/examples/qtconcurrent/imagescaling/main.cpp b/examples/qtconcurrent/imagescaling/main.cpp
new file mode 100644
index 0000000000..de64116f1c
--- /dev/null
+++ b/examples/qtconcurrent/imagescaling/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtGui>
+
+#ifndef QT_NO_CONCURRENT
+
+#include "imagescaling.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc,argv);
+
+ Images imageView;
+ imageView.show();
+
+ return app.exec();
+}
+
+#else
+
+int main()
+{
+ qDebug() << "Qt Concurrent is not supported on this platform";
+}
+
+#endif
diff --git a/examples/qtconcurrent/map/main.cpp b/examples/qtconcurrent/map/main.cpp
new file mode 100644
index 0000000000..bb6c5c657a
--- /dev/null
+++ b/examples/qtconcurrent/map/main.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QImage>
+#include <QList>
+#include <QThread>
+#include <QDebug>
+#include <QApplication>
+#include <qtconcurrentmap.h>
+
+#ifndef QT_NO_CONCURRENT
+
+QImage scale(const QImage &image)
+{
+ qDebug() << "Scaling image in thread" << QThread::currentThread();
+ return image.scaled(QSize(100, 100), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ const int imageCount = 20;
+
+ // Create a list containing imageCount images.
+ QList<QImage> images;
+ for (int i = 0; i < imageCount; ++i)
+ images.append(QImage(1600, 1200, QImage::Format_ARGB32_Premultiplied));
+
+ // Use QtConcurrentBlocking::mapped to apply the scale function to all the
+ // images in the list.
+ QList<QImage> thumbnails = QtConcurrent::blockingMapped(images, scale);
+
+ return 0;
+}
+
+#else
+
+int main()
+{
+ qDebug() << "Qt Concurrent is not yet supported on this platform";
+}
+
+#endif
diff --git a/examples/qtconcurrent/map/map.pro b/examples/qtconcurrent/map/map.pro
new file mode 100644
index 0000000000..76a19964e0
--- /dev/null
+++ b/examples/qtconcurrent/map/map.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = mapdemo
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/map
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/map
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtconcurrent/progressdialog/main.cpp b/examples/qtconcurrent/progressdialog/main.cpp
new file mode 100644
index 0000000000..307baed45b
--- /dev/null
+++ b/examples/qtconcurrent/progressdialog/main.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#ifndef QT_NO_CONCURRENT
+
+using namespace QtConcurrent;
+
+const int iterations = 20;
+
+void spin(int &iteration)
+{
+ const int work = 1000 * 1000 * 40;
+ volatile int v = 0;
+ for (int j = 0; j < work; ++j)
+ ++v;
+
+ qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ // Prepare the vector.
+ QVector<int> vector;
+ for (int i = 0; i < iterations; ++i)
+ vector.append(i);
+
+ // Create a progress dialog.
+ QProgressDialog dialog;
+ dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
+
+ // Create a QFutureWatcher and connect signals and slots.
+ QFutureWatcher<void> futureWatcher;
+ QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
+ QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
+ QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
+ QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
+
+ // Start the computation.
+ futureWatcher.setFuture(QtConcurrent::map(vector, spin));
+
+ // Display the dialog and start the event loop.
+ dialog.exec();
+
+ futureWatcher.waitForFinished();
+
+ // Query the future to check if was canceled.
+ qDebug() << "Canceled?" << futureWatcher.future().isCanceled();
+}
+
+#else
+
+int main()
+{
+ qDebug() << "Qt Concurrent is not yet supported on this platform";
+}
+
+#endif
+
diff --git a/examples/qtconcurrent/progressdialog/progressdialog.pro b/examples/qtconcurrent/progressdialog/progressdialog.pro
new file mode 100644
index 0000000000..9ec11a4ae1
--- /dev/null
+++ b/examples/qtconcurrent/progressdialog/progressdialog.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET +=
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/progressdialog
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/progressdialog
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtconcurrent/qtconcurrent.pro b/examples/qtconcurrent/qtconcurrent.pro
new file mode 100644
index 0000000000..72af020e38
--- /dev/null
+++ b/examples/qtconcurrent/qtconcurrent.pro
@@ -0,0 +1,17 @@
+TEMPLATE = subdirs
+SUBDIRS = imagescaling \
+ map \
+ runfunction \
+ wordcount
+
+!wince* {
+ SUBDIRS += progressdialog
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtconcurrent.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtconcurrent/runfunction/main.cpp b/examples/qtconcurrent/runfunction/main.cpp
new file mode 100644
index 0000000000..1e448bb71d
--- /dev/null
+++ b/examples/qtconcurrent/runfunction/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include <QThread>
+#include <QString>
+#include <qtconcurrentrun.h>
+#include <QApplication>
+
+#ifndef QT_NO_CONCURRENT
+
+using namespace QtConcurrent;
+
+void hello(QString name)
+{
+ qDebug() << "Hello" << name << "from" << QThread::currentThread();
+}
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QFuture<void> f1 = run(hello, QString("Alice"));
+ QFuture<void> f2 = run(hello, QString("Bob"));
+ f1.waitForFinished();
+ f2.waitForFinished();
+}
+
+#else
+
+int main()
+{
+ qDebug() << "Qt Concurrent is not yet supported on this platform";
+}
+
+#endif
diff --git a/examples/qtconcurrent/runfunction/runfunction.pro b/examples/qtconcurrent/runfunction/runfunction.pro
new file mode 100644
index 0000000000..a003d9afe2
--- /dev/null
+++ b/examples/qtconcurrent/runfunction/runfunction.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET +=
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/runfunction
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/runfunction
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp
new file mode 100644
index 0000000000..035207c410
--- /dev/null
+++ b/examples/qtconcurrent/wordcount/main.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QList>
+#include <QMap>
+#include <QTextStream>
+#include <QString>
+#include <QStringList>
+#include <QDir>
+#include <QTime>
+#include <QApplication>
+#include <QDebug>
+
+#include <qtconcurrentmap.h>
+
+#ifndef QT_NO_CONCURRENT
+
+using namespace QtConcurrent;
+
+/*
+ Utility function that recursivily searches for files.
+*/
+QStringList findFiles(const QString &startDir, QStringList filters)
+{
+ QStringList names;
+ QDir dir(startDir);
+
+ foreach (QString file, dir.entryList(filters, QDir::Files))
+ names += startDir + "/" + file;
+
+ foreach (QString subdir, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot))
+ names += findFiles(startDir + "/" + subdir, filters);
+ return names;
+}
+
+typedef QMap<QString, int> WordCount;
+
+/*
+ Single threaded word counter function.
+*/
+WordCount singleThreadedWordCount(QStringList files)
+{
+ WordCount wordCount;
+ foreach (QString file, files) {
+ QFile f(file);
+ f.open(QIODevice::ReadOnly);
+ QTextStream textStream(&f);
+ while (textStream.atEnd() == false)
+ foreach(QString word, textStream.readLine().split(" "))
+ wordCount[word] += 1;
+
+ }
+ return wordCount;
+}
+
+
+// countWords counts the words in a single file. This function is
+// called in parallel by several threads and must be thread
+// safe.
+WordCount countWords(const QString &file)
+{
+ QFile f(file);
+ f.open(QIODevice::ReadOnly);
+ QTextStream textStream(&f);
+ WordCount wordCount;
+
+ while (textStream.atEnd() == false)
+ foreach (QString word, textStream.readLine().split(" "))
+ wordCount[word] += 1;
+
+ return wordCount;
+}
+
+// reduce adds the results from map to the final
+// result. This functor will only be called by one thread
+// at a time.
+void reduce(WordCount &result, const WordCount &w)
+{
+ QMapIterator<QString, int> i(w);
+ while (i.hasNext()) {
+ i.next();
+ result[i.key()] += i.value();
+ }
+}
+
+int main(int argc, char** argv)
+{
+ QApplication app(argc, argv);
+ qDebug() << "finding files...";
+ QStringList files = findFiles("../../", QStringList() << "*.cpp" << "*.h");
+ qDebug() << files.count() << "files";
+
+ qDebug() << "warmup";
+ {
+ QTime time;
+ time.start();
+ WordCount total = singleThreadedWordCount(files);
+ }
+
+ qDebug() << "warmup done";
+
+ int singleThreadTime = 0;
+ {
+ QTime time;
+ time.start();
+ WordCount total = singleThreadedWordCount(files);
+ singleThreadTime = time.elapsed();
+ qDebug() << "single thread" << singleThreadTime;
+ }
+
+ int mapReduceTime = 0;
+ {
+ QTime time;
+ time.start();
+ WordCount total = mappedReduced(files, countWords, reduce);
+ mapReduceTime = time.elapsed();
+ qDebug() << "MapReduce" << mapReduceTime;
+ }
+ qDebug() << "MapReduce speedup x" << ((double)singleThreadTime - (double)mapReduceTime) / (double)mapReduceTime + 1;
+}
+
+#else
+
+int main()
+{
+ qDebug() << "Qt Concurrent is not yet supported on this platform";
+}
+
+#endif
diff --git a/examples/qtconcurrent/wordcount/wordcount.pro b/examples/qtconcurrent/wordcount/wordcount.pro
new file mode 100644
index 0000000000..40ae58891f
--- /dev/null
+++ b/examples/qtconcurrent/wordcount/wordcount.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET +=
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/wordcount
+sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtconcurrent/wordcount
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtestlib/README b/examples/qtestlib/README
new file mode 100644
index 0000000000..e89bf5d726
--- /dev/null
+++ b/examples/qtestlib/README
@@ -0,0 +1,38 @@
+The QTestLib framework is a tool for unit testing Qt based applications
+and libraries. QTestLib provides all the functionality commonly found
+in unit testing frameworks as well as extensions for testing graphical
+user interfaces.
+
+
+The examples in this directory should be run from the command line so
+that output printed to the console can be examined.
+
+Documentation for these examples can be found via the "Tutorial and Examples"
+link in the main Qt documentation.
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/qtestlib/qtestlib.pro b/examples/qtestlib/qtestlib.pro
new file mode 100644
index 0000000000..a7357363eb
--- /dev/null
+++ b/examples/qtestlib/qtestlib.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = tutorial1 tutorial2 tutorial3 tutorial4 tutorial5
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtestlib.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/qtestlib/tutorial1/testqstring.cpp b/examples/qtestlib/tutorial1/testqstring.cpp
new file mode 100644
index 0000000000..79f2bfd782
--- /dev/null
+++ b/examples/qtestlib/tutorial1/testqstring.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtTest/QtTest>
+
+class TestQString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void toUpper();
+};
+//! [0]
+
+//! [1]
+void TestQString::toUpper()
+{
+ QString str = "Hello";
+ QCOMPARE(str.toUpper(), QString("HELLO"));
+}
+//! [1]
+
+//! [2]
+QTEST_MAIN(TestQString)
+#include "testqstring.moc"
+//! [2]
+
diff --git a/examples/qtestlib/tutorial1/tutorial1.pro b/examples/qtestlib/tutorial1/tutorial1.pro
new file mode 100644
index 0000000000..2dd7aef66c
--- /dev/null
+++ b/examples/qtestlib/tutorial1/tutorial1.pro
@@ -0,0 +1,13 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial1
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial1
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C60B
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/qtestlib/tutorial2/testqstring.cpp b/examples/qtestlib/tutorial2/testqstring.cpp
new file mode 100644
index 0000000000..cd0e3f186b
--- /dev/null
+++ b/examples/qtestlib/tutorial2/testqstring.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+//! [0]
+class TestQString: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void toUpper_data();
+ void toUpper();
+};
+//! [0]
+
+//! [1]
+void TestQString::toUpper_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("result");
+
+ QTest::newRow("all lower") << "hello" << "HELLO";
+ QTest::newRow("mixed") << "Hello" << "HELLO";
+ QTest::newRow("all upper") << "HELLO" << "HELLO";
+}
+//! [1]
+
+//! [2]
+void TestQString::toUpper()
+{
+ QFETCH(QString, string);
+ QFETCH(QString, result);
+
+ QCOMPARE(string.toUpper(), result);
+}
+//! [2]
+
+//! [3]
+QTEST_MAIN(TestQString)
+#include "testqstring.moc"
+//! [3]
+
diff --git a/examples/qtestlib/tutorial2/tutorial2.pro b/examples/qtestlib/tutorial2/tutorial2.pro
new file mode 100644
index 0000000000..ed60608c1a
--- /dev/null
+++ b/examples/qtestlib/tutorial2/tutorial2.pro
@@ -0,0 +1,13 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial2
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial2
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C60C
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/qtestlib/tutorial3/testgui.cpp b/examples/qtestlib/tutorial3/testgui.cpp
new file mode 100644
index 0000000000..74b25a8e02
--- /dev/null
+++ b/examples/qtestlib/tutorial3/testgui.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtGui>
+#include <QtTest/QtTest>
+
+class TestGui: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testGui();
+
+};
+//! [0]
+
+//! [1]
+void TestGui::testGui()
+{
+ QLineEdit lineEdit;
+
+ QTest::keyClicks(&lineEdit, "hello world");
+
+ QCOMPARE(lineEdit.text(), QString("hello world"));
+}
+//! [1]
+
+//! [2]
+QTEST_MAIN(TestGui)
+#include "testgui.moc"
+//! [2]
+
diff --git a/examples/qtestlib/tutorial3/tutorial3.pro b/examples/qtestlib/tutorial3/tutorial3.pro
new file mode 100644
index 0000000000..91024b9470
--- /dev/null
+++ b/examples/qtestlib/tutorial3/tutorial3.pro
@@ -0,0 +1,13 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial3
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial3
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C60D
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/qtestlib/tutorial4/testgui.cpp b/examples/qtestlib/tutorial4/testgui.cpp
new file mode 100644
index 0000000000..a1fbbb7d71
--- /dev/null
+++ b/examples/qtestlib/tutorial4/testgui.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtTest/QtTest>
+
+//! [0]
+class TestGui: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testGui_data();
+ void testGui();
+};
+//! [0]
+
+//! [1]
+void TestGui::testGui_data()
+{
+ QTest::addColumn<QTestEventList>("events");
+ QTest::addColumn<QString>("expected");
+
+ QTestEventList list1;
+ list1.addKeyClick('a');
+ QTest::newRow("char") << list1 << "a";
+
+ QTestEventList list2;
+ list2.addKeyClick('a');
+ list2.addKeyClick(Qt::Key_Backspace);
+ QTest::newRow("there and back again") << list2 << "";
+}
+//! [1]
+
+//! [2]
+void TestGui::testGui()
+{
+ QFETCH(QTestEventList, events);
+ QFETCH(QString, expected);
+
+ QLineEdit lineEdit;
+
+ events.simulate(&lineEdit);
+
+ QCOMPARE(lineEdit.text(), expected);
+}
+//! [2]
+
+//! [3]
+QTEST_MAIN(TestGui)
+#include "testgui.moc"
+//! [3]
+
diff --git a/examples/qtestlib/tutorial4/tutorial4.pro b/examples/qtestlib/tutorial4/tutorial4.pro
new file mode 100644
index 0000000000..6d189a255a
--- /dev/null
+++ b/examples/qtestlib/tutorial4/tutorial4.pro
@@ -0,0 +1,13 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial4
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial4
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C60E
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/qtestlib/tutorial5/benchmarking.cpp b/examples/qtestlib/tutorial5/benchmarking.cpp
new file mode 100644
index 0000000000..604eb20a50
--- /dev/null
+++ b/examples/qtestlib/tutorial5/benchmarking.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <qtest.h>
+
+class TestBenchmark : public QObject
+{
+ Q_OBJECT
+private slots:
+ void simple();
+ void multiple_data();
+ void multiple();
+ void series_data();
+ void series();
+};
+
+//! [0]
+void TestBenchmark::simple()
+{
+ QString str1 = QLatin1String("This is a test string");
+ QString str2 = QLatin1String("This is a test string");
+
+ QCOMPARE(str1.localeAwareCompare(str2), 0);
+
+ QBENCHMARK {
+ str1.localeAwareCompare(str2);
+ }
+}
+//! [0]
+
+//! [1]
+void TestBenchmark::multiple_data()
+{
+ QTest::addColumn<bool>("useLocaleCompare");
+ QTest::newRow("locale aware compare") << true;
+ QTest::newRow("standard compare") << false;
+}
+//! [1]
+
+//! [2]
+void TestBenchmark::multiple()
+{
+ QFETCH(bool, useLocaleCompare);
+ QString str1 = QLatin1String("This is a test string");
+ QString str2 = QLatin1String("This is a test string");
+
+ int result;
+ if (useLocaleCompare) {
+ QBENCHMARK {
+ result = str1.localeAwareCompare(str2);
+ }
+ } else {
+ QBENCHMARK {
+ result = (str1 == str2);
+ }
+ }
+}
+//! [2]
+
+//! [3]
+void TestBenchmark::series_data()
+{
+ QTest::addColumn<bool>("useLocaleCompare");
+ QTest::addColumn<int>("stringSize");
+
+ for (int i = 1; i < 10000; i += 2000) {
+ QByteArray size = QByteArray::number(i);
+ QTest::newRow(("locale aware compare--" + size).constData()) << true << i;
+ QTest::newRow(("standard compare--" + size).constData()) << false << i;
+ }
+}
+//! [4]
+
+//! [5]
+void TestBenchmark::series()
+{
+ QFETCH(bool, useLocaleCompare);
+ QFETCH(int, stringSize);
+
+ QString str1 = QString().fill('A', stringSize);
+ QString str2 = QString().fill('A', stringSize);
+ int result;
+ if (useLocaleCompare) {
+ QBENCHMARK {
+ result = str1.localeAwareCompare(str2);
+ }
+ } else {
+ QBENCHMARK {
+ result = (str1 == str2);
+ }
+ }
+}
+//! [5]
+
+QTEST_MAIN(TestBenchmark)
+#include "benchmarking.moc"
diff --git a/examples/qtestlib/tutorial5/containers.cpp b/examples/qtestlib/tutorial5/containers.cpp
new file mode 100644
index 0000000000..b96ba31cc3
--- /dev/null
+++ b/examples/qtestlib/tutorial5/containers.cpp
@@ -0,0 +1,268 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+// This file contains benchmarks for comparing QVector against std::vector
+
+#include <QtCore>
+#include <QVector>
+#include <vector>
+
+#include <qtest.h>
+
+template <typename T> // T is the item type
+class UseCases {
+public:
+ virtual ~UseCases() {}
+
+ // Use case: Insert \a size items into the vector.
+ virtual void insert(int size) = 0;
+
+ // Use case: Lookup \a size items from the vector.
+ virtual void lookup(int size) = 0;
+};
+
+template <typename T>
+T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler
+{
+ return ts;
+}
+
+// This subclass implements the use cases using QVector as efficiently as possible.
+template <typename T>
+class UseCases_QVector : public UseCases<T>
+{
+ void insert(int size)
+ {
+ QVector<T> v;
+ T t;
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ v.append(t);
+ }
+ }
+
+ void lookup(int size)
+ {
+ QVector<T> v;
+
+ T t;
+ for (int i = 0; i < size; ++i)
+ v.append(t);
+
+ T *ts = new T[size];
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ ts[i] = v.value(i);
+ }
+ f<T>(ts);
+ delete[] ts;
+ }
+};
+
+// This subclass implements the use cases using std::vector as efficiently as possible.
+template <typename T>
+class UseCases_stdvector : public UseCases<T>
+{
+ void insert(int size)
+ {
+ std::vector<T> v;
+ T t;
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ v.push_back(t);
+ }
+ }
+
+ void lookup(int size)
+ {
+ std::vector<T> v;
+
+ T t;
+ for (int i = 0; i < size; ++i)
+ v.push_back(t);
+
+ T *ts = new T[size];
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ ts[i] = v[i];
+ }
+ f<T>(ts);
+ delete[] ts;
+ }
+};
+
+struct Large { // A "large" item type
+ int x[1000];
+};
+
+// Symbian devices typically have limited memory
+#ifdef Q_OS_SYMBIAN
+# define LARGE_MAX_SIZE 2000
+#else
+# define LARGE_MAX_SIZE 20000
+#endif
+
+class tst_vector_vs_std : public QObject
+{
+ Q_OBJECT
+public:
+ tst_vector_vs_std()
+ {
+ useCases_QVector_int = new UseCases_QVector<int>;
+ useCases_stdvector_int = new UseCases_stdvector<int>;
+
+ useCases_QVector_Large = new UseCases_QVector<Large>;
+ useCases_stdvector_Large = new UseCases_stdvector<Large>;
+ }
+
+private:
+ UseCases<int> *useCases_QVector_int;
+ UseCases<int> *useCases_stdvector_int;
+ UseCases<Large> *useCases_QVector_Large;
+ UseCases<Large> *useCases_stdvector_Large;
+
+private slots:
+ void insert_int_data();
+ void insert_int();
+ void insert_Large_data();
+ void insert_Large();
+ void lookup_int_data();
+ void lookup_int();
+ void lookup_Large_data();
+ void lookup_Large();
+};
+
+void tst_vector_vs_std::insert_int_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::insert_int()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_int->insert(size);
+ else
+ useCases_QVector_int->insert(size);
+}
+
+void tst_vector_vs_std::insert_Large_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::insert_Large()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_Large->insert(size);
+ else
+ useCases_QVector_Large->insert(size);
+}
+
+//! [1]
+void tst_vector_vs_std::lookup_int_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size;
+ }
+}
+//! [1]
+
+//! [2]
+void tst_vector_vs_std::lookup_int()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_int->lookup(size); // Create a std::vector and run the benchmark.
+ else
+ useCases_QVector_int->lookup(size); // Create a QVector and run the benchmark.
+}
+//! [2]
+
+void tst_vector_vs_std::lookup_Large_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::lookup_Large()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_Large->lookup(size);
+ else
+ useCases_QVector_Large->lookup(size);
+}
+
+QTEST_MAIN(tst_vector_vs_std)
+#include "main.moc"
diff --git a/examples/qtestlib/tutorial5/tutorial5.pro b/examples/qtestlib/tutorial5/tutorial5.pro
new file mode 100644
index 0000000000..47d2e86e08
--- /dev/null
+++ b/examples/qtestlib/tutorial5/tutorial5.pro
@@ -0,0 +1,13 @@
+SOURCES = benchmarking.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial5
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qtestlib/tutorial5
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C60F
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/qws/README b/examples/qws/README
new file mode 100644
index 0000000000..d7cf21a5c5
--- /dev/null
+++ b/examples/qws/README
@@ -0,0 +1,38 @@
+These examples show how to take advantage of features specifically designed
+for use on systems with limited resources, specialized hardware, and small
+screens.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/qws/dbscreen/dbscreen.cpp b/examples/qws/dbscreen/dbscreen.cpp
new file mode 100644
index 0000000000..61953d98c2
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dbscreen.h"
+#include <QApplication>
+
+//! [0]
+bool DBScreen::initDevice()
+{
+ if (!QLinuxFbScreen::initDevice())
+ return false;
+
+ QScreenCursor::initSoftwareCursor();
+ image = new QImage(deviceWidth(), deviceHeight(), pixelFormat());
+ painter = new QPainter(image);
+
+ return true;
+}
+//! [0]
+
+//! [1]
+void DBScreen::shutdownDevice()
+{
+ QLinuxFbScreen::shutdownDevice();
+ delete painter;
+ delete image;
+}
+//! [1]
+
+//! [2]
+void DBScreen::solidFill(const QColor &color, const QRegion &region)
+{
+ QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); i++)
+ painter->fillRect(rects.at(i), color);
+}
+//! [2]
+
+//! [3]
+void DBScreen::blit(const QImage &image, const QPoint &topLeft, const QRegion &region)
+{
+ QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); i++) {
+ QRect destRect = rects.at(i);
+ QRect srcRect(destRect.x()-topLeft.x(), destRect.y()-topLeft.y(), destRect.width(), destRect.height());
+ painter->drawImage(destRect.topLeft(), image, srcRect);
+ }
+}
+//! [3]
+
+//! [4]
+void DBScreen::exposeRegion(QRegion region, int changing)
+{
+ QLinuxFbScreen::exposeRegion(region, changing);
+ QLinuxFbScreen::blit(*image, QPoint(0, 0), region);
+}
+//! [4]
+
diff --git a/examples/qws/dbscreen/dbscreen.h b/examples/qws/dbscreen/dbscreen.h
new file mode 100644
index 0000000000..a708f07f1f
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DBSCREEN_H
+#define DBSCREEN_H
+
+#include <QLinuxFbScreen>
+#include <QPainter>
+
+//! [0]
+class DBScreen : public QLinuxFbScreen
+{
+public:
+ DBScreen(int displayId) : QLinuxFbScreen(displayId) {};
+ ~DBScreen() {}
+ bool initDevice();
+ void shutdownDevice();
+ void blit(const QImage &image, const QPoint &topLeft, const QRegion &region);
+ void solidFill(const QColor &color, const QRegion &region);
+ void exposeRegion(QRegion region, int changing);
+
+private:
+ QPainter *painter;
+ QImage *image;
+};
+//! [0]
+
+#endif // DBSCREEN_H
+
diff --git a/examples/qws/dbscreen/dbscreen.pro b/examples/qws/dbscreen/dbscreen.pro
new file mode 100644
index 0000000000..172a02a5e7
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreen.pro
@@ -0,0 +1,11 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+TARGET = dbscreen
+target.path += $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+HEADERS = dbscreen.h
+SOURCES = dbscreendriverplugin.cpp \
+ dbscreen.cpp
+
diff --git a/examples/qws/dbscreen/dbscreendriverplugin.cpp b/examples/qws/dbscreen/dbscreendriverplugin.cpp
new file mode 100644
index 0000000000..7d70431900
--- /dev/null
+++ b/examples/qws/dbscreen/dbscreendriverplugin.cpp
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QScreenDriverPlugin>
+#include "dbscreen.h"
+
+//! [0]
+class DBScreenDriverPlugin : public QScreenDriverPlugin
+{
+public:
+ DBScreenDriverPlugin();
+ QScreen* create(const QString& key, int displayId);
+ QStringList keys () const;
+};
+//! [0]
+
+DBScreenDriverPlugin::DBScreenDriverPlugin() : QScreenDriverPlugin()
+{
+}
+
+//! [1]
+QScreen* DBScreenDriverPlugin::create(const QString& key, int displayId)
+{
+ if (key.toLower() != "dbscreen")
+ return 0;
+
+ return new DBScreen(displayId);
+}
+//! [1]
+
+//! [2]
+QStringList DBScreenDriverPlugin::keys() const
+{
+ return QStringList() << "dbscreen";
+}
+//! [2] //! [3]
+
+Q_EXPORT_PLUGIN2(dbscreen, DBScreenDriverPlugin)
+//! [3]
diff --git a/examples/qws/framebuffer/framebuffer.pro b/examples/qws/framebuffer/framebuffer.pro
new file mode 100644
index 0000000000..098a97ed14
--- /dev/null
+++ b/examples/qws/framebuffer/framebuffer.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = framebuffer
+CONFIG -= qt
+
+SOURCES += main.c
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/framebuffer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS framebuffer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/framebuffer
+INSTALLS += target sources
diff --git a/examples/qws/framebuffer/main.c b/examples/qws/framebuffer/main.c
new file mode 100644
index 0000000000..ab1a0fd373
--- /dev/null
+++ b/examples/qws/framebuffer/main.c
@@ -0,0 +1,585 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <linux/kd.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <string.h>
+#include <errno.h>
+
+struct fb_var_screeninfo vinfo;
+struct fb_fix_screeninfo finfo;
+char *frameBuffer = 0;
+int fbFd = 0;
+int ttyFd = 0;
+
+void printFixedInfo()
+{
+ printf("Fixed screen info:\n"
+ "\tid: %s\n"
+ "\tsmem_start: 0x%lx\n"
+ "\tsmem_len: %d\n"
+ "\ttype: %d\n"
+ "\ttype_aux: %d\n"
+ "\tvisual: %d\n"
+ "\txpanstep: %d\n"
+ "\typanstep: %d\n"
+ "\tywrapstep: %d\n"
+ "\tline_length: %d\n"
+ "\tmmio_start: 0x%lx\n"
+ "\tmmio_len: %d\n"
+ "\taccel: %d\n"
+ "\n",
+ finfo.id, finfo.smem_start, finfo.smem_len, finfo.type,
+ finfo.type_aux, finfo.visual, finfo.xpanstep, finfo.ypanstep,
+ finfo.ywrapstep, finfo.line_length, finfo.mmio_start,
+ finfo.mmio_len, finfo.accel);
+}
+
+void printVariableInfo()
+{
+ printf("Variable screen info:\n"
+ "\txres: %d\n"
+ "\tyres: %d\n"
+ "\txres_virtual: %d\n"
+ "\tyres_virtual: %d\n"
+ "\tyoffset: %d\n"
+ "\txoffset: %d\n"
+ "\tbits_per_pixel: %d\n"
+ "\tgrayscale: %d\n"
+ "\tred: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tgreen: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tblue: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\ttransp: offset: %2d, length: %2d, msb_right: %2d\n"
+ "\tnonstd: %d\n"
+ "\tactivate: %d\n"
+ "\theight: %d\n"
+ "\twidth: %d\n"
+ "\taccel_flags: 0x%x\n"
+ "\tpixclock: %d\n"
+ "\tleft_margin: %d\n"
+ "\tright_margin: %d\n"
+ "\tupper_margin: %d\n"
+ "\tlower_margin: %d\n"
+ "\thsync_len: %d\n"
+ "\tvsync_len: %d\n"
+ "\tsync: %d\n"
+ "\tvmode: %d\n"
+ "\n",
+ vinfo.xres, vinfo.yres, vinfo.xres_virtual, vinfo.yres_virtual,
+ vinfo.xoffset, vinfo.yoffset, vinfo.bits_per_pixel, vinfo.grayscale,
+ vinfo.red.offset, vinfo.red.length, vinfo.red.msb_right,
+ vinfo.green.offset, vinfo.green.length, vinfo.green.msb_right,
+ vinfo.blue.offset, vinfo.blue.length, vinfo.blue.msb_right,
+ vinfo.transp.offset, vinfo.transp.length, vinfo.transp.msb_right,
+ vinfo.nonstd, vinfo.activate, vinfo.height, vinfo.width,
+ vinfo.accel_flags, vinfo.pixclock, vinfo.left_margin,
+ vinfo.right_margin, vinfo.upper_margin, vinfo.lower_margin,
+ vinfo.hsync_len, vinfo.vsync_len, vinfo.sync, vinfo.vmode);
+}
+
+long switchToGraphicsMode()
+{
+ const char *const devs[] = {"/dev/tty0", "/dev/tty", "/dev/console", 0};
+ const char * const *dev;
+ long oldMode = KD_TEXT;
+
+ for (dev = devs; *dev; ++dev) {
+ ttyFd = open(*dev, O_RDWR);
+ if (ttyFd != -1)
+ break;
+ printf("Opening tty device %s failed: %s\n", *dev, strerror(errno));
+ }
+
+ ioctl(ttyFd, KDGETMODE, &oldMode);
+ if (oldMode == KD_GRAPHICS) {
+ printf("Was in graphics mode already. Skipping\n");
+ return oldMode;
+ }
+ int ret = ioctl(ttyFd, KDSETMODE, KD_GRAPHICS);
+ if (ret == -1) {
+ printf("Switch to graphics mode failed: %s\n", strerror(errno));
+ return oldMode;
+ }
+
+ printf("Successfully switched to graphics mode.\n\n");
+
+ return oldMode;
+}
+
+void restoreTextMode(long oldMode)
+{
+ if (ttyFd == -1)
+ return;
+
+ ioctl(ttyFd, KDSETMODE, oldMode);
+ close(ttyFd);
+}
+
+struct fb_cmap oldPalette;
+struct fb_cmap palette;
+int paletteSize = 0;
+
+void initPalette_16()
+{
+ if (finfo.type == FB_TYPE_PACKED_PIXELS) {
+ // We'll setup a grayscale map for 4bpp linear
+ int val = 0;
+ int i;
+ for (i = 0; i < 16; ++i) {
+ palette.red[i] = (val << 8) | val;
+ palette.green[i] = (val << 8) | val;
+ palette.blue[i] = (val << 8) | val;
+ val += 17;
+ }
+ return;
+ }
+
+ // Default 16 colour palette
+ unsigned char reds[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0xFF, 0xA2,
+ 0x00, 0xFF, 0xFF, 0x00, 0x7F, 0x7F,
+ 0x00, 0x00, 0x00, 0x82 };
+ unsigned char greens[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0xC5,
+ 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00,
+ 0x00, 0x7F, 0x7F, 0x7F };
+ unsigned char blues[16] = { 0x00, 0x7F, 0xBF, 0xFF, 0x00, 0x11,
+ 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x7F,
+ 0x7F, 0x7F, 0x00, 0x00 };
+
+ int i;
+ for (i = 0; i < 16; ++i) {
+ palette.red[i] = ((reds[i]) << 8) | reds[i];
+ palette.green[i] = ((greens[i]) << 8) | greens[i];
+ palette.blue[i] = ((blues[i]) << 8) | blues[i];
+ palette.transp[i] = 0;
+ }
+}
+
+void initPalette_256()
+{
+ if (vinfo.grayscale) {
+ int i;
+ for (i = 0; i < 256; ++i) {
+ unsigned short c = (i << 8) | i;
+ palette.red[i] = c;
+ palette.green[i] = c;
+ palette.blue[i] = c;
+ palette.transp[i] = 0;
+ }
+ return;
+ }
+
+ // 6x6x6 216 color cube
+ int i = 0;
+ int ir, ig, ib;
+ for (ir = 0x0; ir <= 0xff; ir += 0x33) {
+ for (ig = 0x0; ig <= 0xff; ig += 0x33) {
+ for (ib = 0x0; ib <= 0xff; ib += 0x33) {
+ palette.red[i] = (ir << 8)|ir;
+ palette.green[i] = (ig << 8)|ig;
+ palette.blue[i] = (ib << 8)|ib;
+ palette.transp[i] = 0;
+ ++i;
+ }
+ }
+ }
+}
+
+void initPalette()
+{
+ switch (vinfo.bits_per_pixel) {
+ case 8: paletteSize = 256; break;
+ case 4: paletteSize = 16; break;
+ default: break;
+ }
+
+ if (!paletteSize)
+ return; /* not using a palette */
+
+ /* read old palette */
+ oldPalette.start = 0;
+ oldPalette.len = paletteSize;
+ oldPalette.red = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.green = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.blue=(unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ oldPalette.transp=(unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ if (ioctl(ttyFd, FBIOGETCMAP, &oldPalette) == -1)
+ perror("initPalette: error reading palette");
+
+ /* create new palette */
+ palette.start = 0;
+ palette.len = paletteSize;
+ palette.red = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.green = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.blue = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ palette.transp = (unsigned short*)malloc(sizeof(unsigned short)*paletteSize);
+ switch (paletteSize) {
+ case 16: initPalette_16(); break;
+ case 256: initPalette_256(); break;
+ default: break;
+ }
+
+ /* set new palette */
+ if (ioctl(ttyFd, FBIOPUTCMAP, &palette) == -1)
+ perror("initPalette: error setting palette");
+}
+
+void resetPalette()
+{
+ if (paletteSize == 0)
+ return;
+
+ if (ioctl(ttyFd, FBIOPUTCMAP, &oldPalette) == -1)
+ perror("resetPalette");
+
+ free(oldPalette.red);
+ free(oldPalette.green);
+ free(oldPalette.blue);
+ free(oldPalette.transp);
+
+ free(palette.red);
+ free(palette.green);
+ free(palette.blue);
+ free(palette.transp);
+}
+
+void drawRect_rgb32(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 4;
+ const int stride = finfo.line_length / bytesPerPixel;
+
+ int *dest = (int*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb18(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 3;
+ const int stride = finfo.line_length - width * bytesPerPixel;
+ const int red = (color & 0xff0000) >> 16;
+ const int green = (color & 0xff00) >> 8;
+ const int blue = (color & 0xff);
+ const unsigned int packed = (blue >> 2) |
+ ((green >> 2) << 6) |
+ ((red >> 2) << 12);
+ const char color18[3] = { packed & 0xff,
+ (packed & 0xff00) >> 8,
+ (packed & 0xff0000) >> 16 };
+
+ char *dest = (char*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ *dest++ = color18[0];
+ *dest++ = color18[1];
+ *dest++ = color18[2];
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb16(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 2;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const int red = (color & 0xff0000) >> (16 + 3);
+ const int green = (color & 0xff00) >> (8 + 2);
+ const int blue = (color & 0xff) >> 3;
+ const short color16 = blue | (green << 5) | (red << (5 + 6));
+
+ short *dest = (short*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color16;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_rgb15(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 2;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const int red = (color & 0xff0000) >> (16 + 3);
+ const int green = (color & 0xff00) >> (8 + 3);
+ const int blue = (color & 0xff) >> 3;
+ const short color15 = blue | (green << 5) | (red << (5 + 5));
+
+ short *dest = (short*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color15;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect_palette(int x0, int y0, int width, int height, int color)
+{
+ const int bytesPerPixel = 1;
+ const int stride = finfo.line_length / bytesPerPixel;
+ const unsigned char color8 = color;
+
+ unsigned char *dest = (unsigned char*)(frameBuffer)
+ + (y0 + vinfo.yoffset) * stride
+ + (x0 + vinfo.xoffset);
+
+ int x, y;
+ for (y = 0; y < height; ++y) {
+ for (x = 0; x < width; ++x) {
+ dest[x] = color8;
+ }
+ dest += stride;
+ }
+}
+
+void drawRect(int x0, int y0, int width, int height, int color)
+{
+ switch (vinfo.bits_per_pixel) {
+ case 32:
+ drawRect_rgb32(x0, y0, width, height, color);
+ break;
+ case 18:
+ drawRect_rgb18(x0, y0, width, height, color);
+ break;
+ case 16:
+ drawRect_rgb16(x0, y0, width, height, color);
+ break;
+ case 15:
+ drawRect_rgb15(x0, y0, width, height, color);
+ break;
+ case 8:
+ drawRect_palette(x0, y0, width, height, color);
+ break;
+ case 4:
+ drawRect_palette(x0, y0, width, height, color);
+ break;
+ default:
+ printf("Warning: drawRect() not implemented for color depth %i\n",
+ vinfo.bits_per_pixel);
+ break;
+ }
+}
+
+#define PERFORMANCE_RUN_COUNT 5
+void performSpeedTest(void* fb, int fbSize)
+{
+ int i, j, run;
+
+ struct timeval startTime, endTime;
+ unsigned long long results[PERFORMANCE_RUN_COUNT];
+ unsigned long long average;
+
+ unsigned int* testImage;
+
+ unsigned int randData[17] = {
+ 0x3A428472, 0x724B84D3, 0x26B898AB, 0x7D980E3C, 0x5345A084,
+ 0x6779B66B, 0x791EE4B4, 0x6E8EE3CC, 0x63AF504A, 0x18A21B33,
+ 0x0E26EB73, 0x022F708E, 0x1740F3B0, 0x7E2C699D, 0x0E8A570B,
+ 0x5F2C22FB, 0x6A742130
+ };
+
+ printf("Frame Buffer Performance test...\n");
+
+ for (run=0; run<PERFORMANCE_RUN_COUNT; ++run) {
+
+ /* Generate test image with random(ish) data: */
+ testImage = (unsigned int*) malloc(fbSize);
+ j = run;
+ for (i=0; i < (int)(fbSize / sizeof(int)); ++i) {
+ testImage[i] = randData[j];
+ j++;
+ if (j >= 17)
+ j = 0;
+ }
+
+ gettimeofday(&startTime, NULL);
+ memcpy(fb, testImage, fbSize);
+ gettimeofday(&endTime, NULL);
+
+ long secsDiff = endTime.tv_sec - startTime.tv_sec;
+ results[run] = secsDiff * 1000000 + (endTime.tv_usec - startTime.tv_usec);
+
+ free(testImage);
+ }
+
+
+ average = 0;
+ for (i=0; i<PERFORMANCE_RUN_COUNT; ++i)
+ average += results[i];
+ average = average / PERFORMANCE_RUN_COUNT;
+
+ printf(" Average: %llu usecs\n", average);
+ printf(" Bandwidth: %.03f MByte/Sec\n", (fbSize / 1048576.0) / ((double)average / 1000000.0));
+ printf(" Max. FPS: %.03f fps\n\n", 1000000.0 / (double)average);
+
+ /* Clear the framebuffer back to black again: */
+ memset(fb, 0, fbSize);
+}
+
+int main(int argc, char **argv)
+{
+ long int screensize = 0;
+ int doGraphicsMode = 1;
+ long oldKdMode = KD_TEXT;
+ const char *devfile = "/dev/fb0";
+ int nextArg = 1;
+
+ if (nextArg < argc) {
+ if (strncmp("nographicsmodeswitch", argv[nextArg],
+ strlen("nographicsmodeswitch")) == 0)
+ {
+ ++nextArg;
+ doGraphicsMode = 0;
+ }
+ }
+ if (nextArg < argc)
+ devfile = argv[nextArg++];
+
+ /* Open the file for reading and writing */
+ fbFd = open(devfile, O_RDWR);
+ if (fbFd == -1) {
+ perror("Error: cannot open framebuffer device");
+ exit(1);
+ }
+ printf("The framebuffer device was opened successfully.\n\n");
+
+ /* Get fixed screen information */
+ if (ioctl(fbFd, FBIOGET_FSCREENINFO, &finfo) == -1) {
+ perror("Error reading fixed information");
+ exit(2);
+ }
+
+ printFixedInfo();
+
+ /* Figure out the size of the screen in bytes */
+ screensize = finfo.smem_len;
+
+ /* Map the device to memory */
+ frameBuffer = (char *)mmap(0, screensize,
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ fbFd, 0);
+ if (frameBuffer == MAP_FAILED) {
+ perror("Error: Failed to map framebuffer device to memory");
+ exit(4);
+ }
+ printf("The framebuffer device was mapped to memory successfully.\n"
+ "\n");
+
+ if (doGraphicsMode)
+ oldKdMode = switchToGraphicsMode();
+
+ /* Get variable screen information */
+ if (ioctl(fbFd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+ perror("Error reading variable information");
+ exit(3);
+ }
+
+ printVariableInfo();
+
+ performSpeedTest(frameBuffer, screensize);
+
+ initPalette();
+
+ if (paletteSize == 0) {
+ printf("Will draw 3 rectangles on the screen,\n"
+ "they should be colored red, green and blue (in that order).\n");
+ drawRect(vinfo.xres / 8, vinfo.yres / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xffff0000);
+ drawRect(vinfo.xres * 3 / 8, vinfo.yres * 3 / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xff00ff00);
+ drawRect(vinfo.xres * 5 / 8, vinfo.yres * 5 / 8,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 0xff0000ff);
+ } else {
+ printf("Will rectangles from the 16 first entries in the color palette"
+ " on the screen\n");
+ int y;
+ int x;
+ for (y = 0; y < 4; ++y) {
+ for (x = 0; x < 4; ++x) {
+ drawRect(vinfo.xres / 4 * x, vinfo.yres / 4 * y,
+ vinfo.xres / 4, vinfo.yres / 4,
+ 4 * y + x);
+ }
+ }
+ }
+
+ sleep(5);
+
+ resetPalette();
+
+ printf(" Done.\n");
+
+ if (doGraphicsMode)
+ restoreTextMode(oldKdMode);
+
+ munmap(frameBuffer, screensize);
+ close(fbFd);
+ return 0;
+}
diff --git a/examples/qws/mousecalibration/calibration.cpp b/examples/qws/mousecalibration/calibration.cpp
new file mode 100644
index 0000000000..c0746c9aeb
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "calibration.h"
+
+#include <QWSPointerCalibrationData>
+#include <QPainter>
+#include <QFile>
+#include <QTimer>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QMouseEvent>
+#include <QScreen>
+#include <QWSServer>
+
+//! [0]
+Calibration::Calibration()
+{
+ QRect desktop = QApplication::desktop()->geometry();
+ desktop.moveTo(QPoint(0, 0));
+ setGeometry(desktop);
+
+ setFocusPolicy(Qt::StrongFocus);
+ setFocus();
+ setModal(true);
+//! [0]
+
+//! [1]
+ int width = qt_screen->deviceWidth();
+ int height = qt_screen->deviceHeight();
+
+ int dx = width / 10;
+ int dy = height / 10;
+
+ QPoint *points = data.screenPoints;
+ points[QWSPointerCalibrationData::TopLeft] = QPoint(dx, dy);
+ points[QWSPointerCalibrationData::BottomLeft] = QPoint(dx, height - dy);
+ points[QWSPointerCalibrationData::BottomRight] = QPoint(width - dx, height - dy);
+ points[QWSPointerCalibrationData::TopRight] = QPoint(width - dx, dy);
+ points[QWSPointerCalibrationData::Center] = QPoint(width / 2, height / 2);
+//! [1]
+
+//! [2]
+ pressCount = 0;
+}
+//! [2]
+
+//! [3]
+Calibration::~Calibration()
+{
+}
+//! [3]
+
+//! [4]
+int Calibration::exec()
+{
+ QWSServer::mouseHandler()->clearCalibration();
+ grabMouse();
+ activateWindow();
+ int ret = QDialog::exec();
+ releaseMouse();
+ return ret;
+}
+//! [4]
+
+//! [5]
+void Calibration::paintEvent(QPaintEvent*)
+{
+ QPainter p(this);
+ p.fillRect(rect(), Qt::white);
+
+ QPoint point = data.screenPoints[pressCount];
+
+ // Map to logical coordinates in case the screen is transformed
+ QSize screenSize(qt_screen->deviceWidth(), qt_screen->deviceHeight());
+ point = qt_screen->mapFromDevice(point, screenSize);
+
+ p.fillRect(point.x() - 6, point.y() - 1, 13, 3, Qt::black);
+ p.fillRect(point.x() - 1, point.y() - 6, 3, 13, Qt::black);
+}
+//! [5]
+
+//! [6]
+void Calibration::mouseReleaseEvent(QMouseEvent *event)
+{
+ // Map from device coordinates in case the screen is transformed
+ QSize screenSize(qt_screen->width(), qt_screen->height());
+ QPoint p = qt_screen->mapToDevice(event->pos(), screenSize);
+
+ data.devPoints[pressCount] = p;
+
+ if (++pressCount < 5)
+ repaint();
+ else
+ accept();
+}
+//! [6]
+
+//! [7]
+void Calibration::accept()
+{
+ Q_ASSERT(pressCount == 5);
+ QWSServer::mouseHandler()->calibrate(&data);
+ QDialog::accept();
+}
+//! [7]
+
diff --git a/examples/qws/mousecalibration/calibration.h b/examples/qws/mousecalibration/calibration.h
new file mode 100644
index 0000000000..4988b6e755
--- /dev/null
+++ b/examples/qws/mousecalibration/calibration.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALIBRATION_H
+#define CALIBRATION_H
+
+#include <QDialog>
+#include <QWSPointerCalibrationData>
+
+//! [0]
+class Calibration : public QDialog
+{
+public:
+ Calibration();
+ ~Calibration();
+ int exec();
+
+protected:
+ void paintEvent(QPaintEvent*);
+ void mouseReleaseEvent(QMouseEvent*);
+ void accept();
+
+private:
+ QWSPointerCalibrationData data;
+ int pressCount;
+};
+//! [0]
+
+
+#endif
diff --git a/examples/qws/mousecalibration/main.cpp b/examples/qws/mousecalibration/main.cpp
new file mode 100644
index 0000000000..3db11cd109
--- /dev/null
+++ b/examples/qws/mousecalibration/main.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QMessageBox>
+#include <QTimer>
+#include <QWSServer>
+
+#include "calibration.h"
+#include "scribblewidget.h"
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv, QApplication::GuiServer);
+
+ if (!QWSServer::mouseHandler())
+ qFatal("No mouse handler installed");
+
+ {
+ QMessageBox message;
+ message.setText("<p>Please press once at each of the marks "
+ "shown in the next screen.</p>"
+ "<p>This messagebox will timout after 10 seconds "
+ "if you are unable to close it.</p>");
+ QTimer::singleShot(10 * 1000, &message, SLOT(accept()));
+ message.exec();
+ }
+
+//! [0] //! [1]
+ Calibration cal;
+ cal.exec();
+//! [1]
+
+//! [2]
+ {
+ QMessageBox message;
+ message.setText("<p>The next screen will let you test the calibration "
+ "by drawing into a widget.</p><p>This program will "
+ "automatically close after 20 seconds.<p>");
+ QTimer::singleShot(10 * 1000, &message, SLOT(accept()));
+ message.exec();
+ }
+
+ ScribbleWidget scribble;
+ scribble.showMaximized();
+ scribble.show();
+
+ app.setActiveWindow(&scribble);
+ QTimer::singleShot(20 * 1000, &app, SLOT(quit()));
+
+ return app.exec();
+}
+//! [2]
+
diff --git a/examples/qws/mousecalibration/mousecalibration.pro b/examples/qws/mousecalibration/mousecalibration.pro
new file mode 100644
index 0000000000..878aff23bc
--- /dev/null
+++ b/examples/qws/mousecalibration/mousecalibration.pro
@@ -0,0 +1,11 @@
+HEADERS += calibration.h \
+ scribblewidget.h
+SOURCES += calibration.cpp \
+ scribblewidget.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/mousecalibration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/mousecalibration
+INSTALLS += target sources
diff --git a/examples/qws/mousecalibration/scribblewidget.cpp b/examples/qws/mousecalibration/scribblewidget.cpp
new file mode 100644
index 0000000000..cc24aeb3bf
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "scribblewidget.h"
+
+ScribbleWidget::ScribbleWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ scribbling = false;
+}
+
+void ScribbleWidget::resizeEvent(QResizeEvent *e)
+{
+ image = QImage(e->size(), QImage::Format_RGB32);
+ image.fill(QColor(Qt::white).rgb());
+}
+
+void ScribbleWidget::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() != Qt::LeftButton)
+ return;
+
+ lastPoint = event->pos();
+ scribbling = true;
+}
+
+void ScribbleWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && scribbling)
+ drawLineTo(event->pos());
+}
+
+void ScribbleWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && scribbling) {
+ drawLineTo(event->pos());
+ scribbling = false;
+ }
+}
+
+void ScribbleWidget::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.drawImage(QPoint(0, 0), image);
+}
+
+void ScribbleWidget::drawLineTo(const QPoint &endPoint)
+{
+ QPainter painter(&image);
+ painter.setPen(QPen(Qt::blue, 1, Qt::SolidLine,
+ Qt::RoundCap, Qt::RoundJoin));
+ painter.drawLine(lastPoint, endPoint);
+ update();
+ lastPoint = endPoint;
+}
diff --git a/examples/qws/mousecalibration/scribblewidget.h b/examples/qws/mousecalibration/scribblewidget.h
new file mode 100644
index 0000000000..a8957b4664
--- /dev/null
+++ b/examples/qws/mousecalibration/scribblewidget.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIBBLEWIDGET_H
+#define SCRIBBLEWIDGET_H
+
+#include <QLabel>
+#include <QMouseEvent>
+#include <QResizeEvent>
+#include <QImage>
+#include <QPainter>
+
+class ScribbleWidget : public QWidget
+{
+public:
+ ScribbleWidget(QWidget *parent = 0);
+
+ void resizeEvent(QResizeEvent *e);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *);
+
+private:
+ void drawLineTo(const QPoint &endPoint);
+
+private:
+ bool scribbling;
+ QPoint lastPoint;
+ QImage image;
+};
+
+#endif // SCRIBBLEWIDGET_H
diff --git a/examples/qws/qws.pro b/examples/qws/qws.pro
new file mode 100644
index 0000000000..7736625cbe
--- /dev/null
+++ b/examples/qws/qws.pro
@@ -0,0 +1,9 @@
+TEMPLATE = subdirs
+# no /dev/fbX
+!qnx:!vxworks:SUBDIRS = framebuffer
+SUBDIRS += mousecalibration simpledecoration
+
+# install
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS README *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws
+INSTALLS += sources
diff --git a/examples/qws/simpledecoration/analogclock.cpp b/examples/qws/simpledecoration/analogclock.cpp
new file mode 100644
index 0000000000..4a91e0dc0a
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "analogclock.h"
+
+AnalogClock::AnalogClock(QWidget *parent)
+ : QWidget(parent)
+{
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ timer->start(1000);
+
+ setWindowTitle(tr("Analog Clock"));
+ resize(200, 200);
+}
+
+void AnalogClock::paintEvent(QPaintEvent *)
+{
+ static const QPoint hourHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -40)
+ };
+ static const QPoint minuteHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -70)
+ };
+
+ QColor hourColor(127, 0, 127);
+ QColor minuteColor(0, 127, 127, 191);
+
+ int side = qMin(width(), height());
+ QTime time = QTime::currentTime();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.translate(width() / 2, height() / 2);
+ painter.scale(side / 200.0, side / 200.0);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(hourColor);
+
+ painter.save();
+ painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
+ painter.drawConvexPolygon(hourHand, 3);
+ painter.restore();
+
+ painter.setPen(hourColor);
+
+ for (int i = 0; i < 12; ++i) {
+ painter.drawLine(88, 0, 96, 0);
+ painter.rotate(30.0);
+ }
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(minuteColor);
+
+ painter.save();
+ painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
+ painter.drawConvexPolygon(minuteHand, 3);
+ painter.restore();
+
+ painter.setPen(minuteColor);
+
+ for (int j = 0; j < 60; ++j) {
+ if ((j % 5) != 0)
+ painter.drawLine(92, 0, 96, 0);
+ painter.rotate(6.0);
+ }
+}
diff --git a/examples/qws/simpledecoration/analogclock.h b/examples/qws/simpledecoration/analogclock.h
new file mode 100644
index 0000000000..6fef764ee1
--- /dev/null
+++ b/examples/qws/simpledecoration/analogclock.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANALOGCLOCK_H
+#define ANALOGCLOCK_H
+
+#include <QWidget>
+
+class AnalogClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AnalogClock(QWidget *parent = 0);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+};
+
+#endif
diff --git a/examples/qws/simpledecoration/main.cpp b/examples/qws/simpledecoration/main.cpp
new file mode 100644
index 0000000000..9a8f913ee5
--- /dev/null
+++ b/examples/qws/simpledecoration/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "analogclock.h"
+#include "mydecoration.h"
+
+//! [create application]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MyDecoration *decoration = new MyDecoration();
+ app.qwsSetDecoration(decoration);
+//! [create application]
+
+//! [start application]
+ AnalogClock clock;
+ clock.show();
+
+ return app.exec();
+}
+//! [start application]
diff --git a/examples/qws/simpledecoration/mydecoration.cpp b/examples/qws/simpledecoration/mydecoration.cpp
new file mode 100644
index 0000000000..32db90596e
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.cpp
@@ -0,0 +1,374 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mydecoration.h"
+
+/* XPM */
+static const char * const _close_button[] = {
+"16 16 3 1",
+" c none",
+". c #ffafaf",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x.x........x.x ",
+" x..x......x..x ",
+" x...x....x...x ",
+" x....x..x....x ",
+" x.....xx.....x ",
+" x.....xx.....x ",
+" x....x..x....x ",
+" x...x....x...x ",
+" x..x......x..x ",
+" x.x........x.x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _normalize_button[] = {
+"16 16 4 1",
+" c none",
+". c #dfdfff",
+"o c #7f7f7f",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" xx...........x ",
+" x.x..........x ",
+" x..x..x......x ",
+" x...xxx......x ",
+" x...xxx......x ",
+" x..xxxx......x ",
+" x............x ",
+" x.......xxxx.x ",
+" x.......x..x.x ",
+" x.......x..x.x ",
+" x.......xxxx.x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _maximize_button[] = {
+"16 16 4 1",
+" c none",
+". c #dfdfff",
+"o c #7f7f7f",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x.......xxxx.x ",
+" x........xxx.x ",
+" x........xxx.x ",
+" x.......x..x.x ",
+" x......x.....x ",
+" x.....x......x ",
+" x.oooo.......x ",
+" x.o..o.......x ",
+" x.o..o.......x ",
+" x.oooo.......x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+static const char * const _help_button[] = {
+"16 16 3 1",
+" c none",
+". c #afffdf",
+"x c #000000",
+" ",
+" xxxxxxxxxxxxxx ",
+" x............x ",
+" x....xxxx....x ",
+" x..xx....xx..x ",
+" x.xx......xx.x ",
+" x.xx......xx.x ",
+" x........xx..x ",
+" x......xx....x ",
+" x.....xx.....x ",
+" x.....xx.....x ",
+" x............x ",
+" x.....xx.....x ",
+" x............x ",
+" xxxxxxxxxxxxxx ",
+" "};
+
+//! [constructor start]
+MyDecoration::MyDecoration()
+ : QDecorationDefault()
+{
+ border = 4;
+ titleHeight = 24;
+ buttonWidth = 20;
+ buttonHeight = 20;
+ buttonMargin = 2;
+ buttonHints << Qt::Window
+ << Qt::WindowMaximizeButtonHint
+ << Qt::WindowContextHelpButtonHint;
+ //! [constructor start]
+
+ //! [map window flags to decoration regions]
+ buttonHintMap[Qt::Window] = Close;
+ buttonHintMap[Qt::WindowMaximizeButtonHint] = Maximize;
+ buttonHintMap[Qt::WindowContextHelpButtonHint] = Help;
+ //! [map window flags to decoration regions]
+
+ //! [map decoration regions to pixmaps]
+ normalButtonPixmaps[Close] = QPixmap(_close_button);
+ normalButtonPixmaps[Maximize] = QPixmap(_maximize_button);
+ normalButtonPixmaps[Normalize] = QPixmap(_normalize_button);
+ normalButtonPixmaps[Help] = QPixmap(_help_button);
+
+ maximizedButtonPixmaps[Close] = QPixmap(_close_button);
+ maximizedButtonPixmaps[Maximize] = QPixmap(_normalize_button);
+ maximizedButtonPixmaps[Normalize] = QPixmap(_normalize_button);
+ maximizedButtonPixmaps[Help] = QPixmap(_help_button);
+ //! [map decoration regions to pixmaps]
+
+ //! [constructor end]
+ stateRegions << Close << Maximize << Help;
+}
+//! [constructor end]
+
+//! [region start]
+QRegion MyDecoration::region(const QWidget *widget, const QRect &insideRect,
+ int decorationRegion)
+{
+ //! [region start]
+ //! [calculate the positions of buttons based on the window flags used]
+ QHash<DecorationRegion, int> buttons;
+ Qt::WindowFlags flags = widget->windowFlags();
+ int dx = -buttonMargin - buttonWidth;
+
+ foreach (Qt::WindowType button, buttonHints) {
+ if (flags & button) {
+ int x = (buttons.size() + 1) * dx;
+ buttons[buttonHintMap[button]] = x;
+ }
+ }
+ //! [calculate the positions of buttons based on the window flags used]
+
+ //! [calculate the extent of the title]
+ int titleRightMargin = buttons.size() * dx;
+
+ QRect outsideRect(insideRect.left() - border,
+ insideRect.top() - titleHeight - border,
+ insideRect.width() + 2 * border,
+ insideRect.height() + titleHeight + 2 * border);
+ //! [calculate the extent of the title]
+
+ //! [check for all regions]
+ QRegion region;
+
+ if (decorationRegion == All) {
+ region += QRegion(outsideRect) - QRegion(insideRect);
+ return region;
+ }
+ //! [check for all regions]
+
+ //! [compose a region based on the decorations specified]
+ if (decorationRegion & Title) {
+ QRect rect = outsideRect.adjusted(border, border, -border, 0);
+ rect.setHeight(titleHeight);
+
+ // Adjust the width to accommodate buttons.
+ rect.setWidth(qMax(0, rect.width() + titleRightMargin));
+ region += rect;
+ }
+ if (decorationRegion & Top) {
+ QRect rect = outsideRect.adjusted(border, 0, -border, 0);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & Left) {
+ QRect rect = outsideRect.adjusted(0, border, 0, -border);
+ rect.setWidth(border);
+ region += rect;
+ }
+ if (decorationRegion & Right) {
+ QRect rect = outsideRect.adjusted(0, border, 0, -border);
+ rect.setLeft(rect.right() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & Bottom) {
+ QRect rect = outsideRect.adjusted(border, 0, -border, 0);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & TopLeft) {
+ QRect rect = outsideRect;
+ rect.setWidth(border);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & TopRight) {
+ QRect rect = outsideRect;
+ rect.setLeft(rect.right() + 1 - border);
+ rect.setHeight(border);
+ region += rect;
+ }
+ if (decorationRegion & BottomLeft) {
+ QRect rect = outsideRect;
+ rect.setWidth(border);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ if (decorationRegion & BottomRight) {
+ QRect rect = outsideRect;
+ rect.setLeft(rect.right() + 1 - border);
+ rect.setTop(rect.bottom() + 1 - border);
+ region += rect;
+ }
+ //! [compose a region based on the decorations specified]
+
+ //! [add a region for each button only if it is present]
+ foreach (QDecoration::DecorationRegion testRegion, stateRegions) {
+ if (decorationRegion & testRegion and buttons.contains(testRegion)) {
+ // Inside the title rectangle
+ QRect rect = outsideRect.adjusted(border, border, -border, 0);
+ rect.setHeight(titleHeight);
+
+ dx = buttons[testRegion];
+ rect.setLeft(rect.right() + 1 + dx);
+ rect.setWidth(buttonWidth + buttonMargin);
+ region += rect;
+ }
+ }
+ //! [add a region for each button only if it is present]
+
+ //! [region end]
+ return region;
+}
+//! [region end]
+
+//! [paint start]
+bool MyDecoration::paint(QPainter *painter, const QWidget *widget,
+ int decorationRegion, DecorationState state)
+{
+ if (decorationRegion == None)
+ return false;
+ //! [paint start]
+
+ //! [paint different regions]
+ bool handled = false;
+
+ QPalette palette = QApplication::palette();
+ QHash<DecorationRegion, QPixmap> buttonPixmaps;
+
+ if (widget->windowState() == Qt::WindowMaximized)
+ buttonPixmaps = maximizedButtonPixmaps;
+ else
+ buttonPixmaps = normalButtonPixmaps;
+
+ if (decorationRegion & Title) {
+ QRect rect = QDecoration::region(widget, Title).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Base));
+ painter->save();
+ painter->setPen(QPen(palette.color(QPalette::Text)));
+ painter->drawText(rect, Qt::AlignCenter, widget->windowTitle());
+ painter->restore();
+ handled = true;
+ }
+ if (decorationRegion & Top) {
+ QRect rect = QDecoration::region(widget, Top).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Left) {
+ QRect rect = QDecoration::region(widget, Left).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Right) {
+ QRect rect = QDecoration::region(widget, Right).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & Bottom) {
+ QRect rect = QDecoration::region(widget, Bottom).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & TopLeft) {
+ QRect rect = QDecoration::region(widget, TopLeft).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & TopRight) {
+ QRect rect = QDecoration::region(widget, TopRight).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & BottomLeft) {
+ QRect rect = QDecoration::region(widget, BottomLeft).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ if (decorationRegion & BottomRight) {
+ QRect rect = QDecoration::region(widget, BottomRight).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Dark));
+ handled = true;
+ }
+ //! [paint different regions]
+
+ //! [paint buttons]
+ int margin = (titleHeight - 16) / 2;
+ Qt::WindowFlags flags = widget->windowFlags();
+
+ foreach (DecorationRegion testRegion, stateRegions) {
+ if (decorationRegion & testRegion && flags & buttonHintMap.key(testRegion)) {
+ QRect rect = QDecoration::region(
+ widget, testRegion).boundingRect();
+ painter->fillRect(rect, palette.brush(QPalette::Base));
+
+ QRect buttonRect = rect.adjusted(0, margin, -buttonMargin - margin,
+ -buttonMargin);
+ painter->drawPixmap(buttonRect.topLeft(), buttonPixmaps[testRegion]);
+ handled = true;
+ }
+ }
+ //! [paint buttons]
+
+ //! [paint end]
+ return handled;
+}
+//! [paint end]
diff --git a/examples/qws/simpledecoration/mydecoration.h b/examples/qws/simpledecoration/mydecoration.h
new file mode 100644
index 0000000000..6d8aebf6b2
--- /dev/null
+++ b/examples/qws/simpledecoration/mydecoration.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYDECORATION_H
+#define MYDECORATION_H
+
+#include <QDecorationDefault>
+#include <QHash>
+#include <QPixmap>
+#include <QRegion>
+#include <Qt>
+
+//! [decoration class definition]
+class MyDecoration : public QDecorationDefault
+{
+public:
+ MyDecoration();
+ QRegion region(const QWidget *widget, const QRect &insideRect, int decorationRegion);
+ bool paint(QPainter *painter, const QWidget *widget, int decorationRegion, DecorationState state);
+
+private:
+ int border;
+ int buttonHeight;
+ int buttonMargin;
+ int buttonWidth;
+ int titleHeight;
+ QHash<Qt::WindowType, DecorationRegion> buttonHintMap;
+ QHash<DecorationRegion, QPixmap> normalButtonPixmaps;
+ QHash<DecorationRegion, QPixmap> maximizedButtonPixmaps;
+ QVector<Qt::WindowType> buttonHints;
+ QVector<DecorationRegion> stateRegions;
+};
+//! [decoration class definition]
+
+#endif
diff --git a/examples/qws/simpledecoration/simpledecoration.pro b/examples/qws/simpledecoration/simpledecoration.pro
new file mode 100644
index 0000000000..2a4e0be51c
--- /dev/null
+++ b/examples/qws/simpledecoration/simpledecoration.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+HEADERS = analogclock.h \
+ mydecoration.h
+SOURCES = analogclock.cpp \
+ main.cpp \
+ mydecoration.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/qws/simpledecoration
+INSTALLS += target sources
diff --git a/examples/qws/svgalib/README b/examples/qws/svgalib/README
new file mode 100644
index 0000000000..227c066f01
--- /dev/null
+++ b/examples/qws/svgalib/README
@@ -0,0 +1,9 @@
+This is the SVGA screen driver plugin example for QWS.
+
+You may need to set the SVGALIB_DEFAULT_MODE environment
+variable. These values have been confirmed to work on one specific
+machine using svgalib 1.4.3: 18, 24, 34, 35, 36
+
+There is a bug in the example causing missing updates in 8-bit mode
+(e.g. modes 10 and 12). Fixing this bug is left as an exercise for the
+reader.
diff --git a/examples/qws/svgalib/svgalib.pro b/examples/qws/svgalib/svgalib.pro
new file mode 100644
index 0000000000..8a47c1d1d0
--- /dev/null
+++ b/examples/qws/svgalib/svgalib.pro
@@ -0,0 +1,19 @@
+TEMPLATE = lib
+CONFIG += plugin
+
+LIBS += -lvgagl -lvga
+
+TARGET = svgalibscreen
+target.path = $$[QT_INSTALL_PLUGINS]/gfxdrivers
+INSTALLS += target
+
+HEADERS = svgalibscreen.h \
+ svgalibpaintengine.h \
+ svgalibsurface.h \
+ svgalibpaintdevice.h
+SOURCES = svgalibscreen.cpp \
+ svgalibpaintengine.cpp \
+ svgalibsurface.cpp \
+ svgalibpaintdevice.cpp \
+ svgalibplugin.cpp
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.cpp b/examples/qws/svgalib/svgalibpaintdevice.cpp
new file mode 100644
index 0000000000..5b1ecb0717
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintdevice.h"
+#include "svgalibpaintengine.h"
+
+#include <QApplication>
+#include <QDesktopWidget>
+
+SvgalibPaintDevice::SvgalibPaintDevice(QWidget *w)
+ : QCustomRasterPaintDevice(w)
+{
+ pengine = new SvgalibPaintEngine(this);
+}
+
+SvgalibPaintDevice::~SvgalibPaintDevice()
+{
+ delete pengine;
+}
+
+int SvgalibPaintDevice::metric(PaintDeviceMetric m) const
+{
+ if (m == PdmWidth)
+ return QApplication::desktop()->screenGeometry().width();
+ else if (m == PdmHeight)
+ return QApplication::desktop()->screenGeometry().height();
+ return QCustomRasterPaintDevice::metric(m);
+}
+
diff --git a/examples/qws/svgalib/svgalibpaintdevice.h b/examples/qws/svgalib/svgalibpaintdevice.h
new file mode 100644
index 0000000000..0b70b86df9
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintdevice.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 SVGALIBPAINTDEVICE_H
+#define SVGALIBPAINTDEVICE_H
+
+#include "svgalibpaintengine.h"
+#include <private/qpaintengine_raster_p.h>
+#include <qscreen_qws.h>
+
+//! [0]
+class SvgalibPaintDevice : public QCustomRasterPaintDevice
+{
+public:
+ SvgalibPaintDevice(QWidget *w);
+ ~SvgalibPaintDevice();
+
+ void* memory() const { return QScreen::instance()->base(); }
+
+ QPaintEngine *paintEngine() const { return pengine; }
+ int metric(PaintDeviceMetric m) const;
+
+private:
+ SvgalibPaintEngine *pengine;
+};
+//! [0]
+
+#endif // SVGALIBPAINTDEVICE_H
diff --git a/examples/qws/svgalib/svgalibpaintengine.cpp b/examples/qws/svgalib/svgalibpaintengine.cpp
new file mode 100644
index 0000000000..f6774d0683
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibpaintengine.h"
+
+#include <QColor>
+#include <vga.h>
+#include <vgagl.h>
+
+SvgalibPaintEngine::SvgalibPaintEngine(QPaintDevice *device)
+ : QRasterPaintEngine(device)
+{
+}
+
+SvgalibPaintEngine::~SvgalibPaintEngine()
+{
+}
+
+//! [0]
+bool SvgalibPaintEngine::begin(QPaintDevice *dev)
+{
+ device = dev;
+ pen = Qt::NoPen;
+ simplePen = true;
+ brush = Qt::NoBrush;
+ simpleBrush = true;
+ matrix = QTransform();
+ simpleMatrix = true;
+ setClip(QRect(0, 0, device->width(), device->height()));
+ opaque = true;
+ aliased = true;
+ sourceOver = true;
+
+ return QRasterPaintEngine::begin(dev);
+}
+//! [0]
+
+//! [1]
+bool SvgalibPaintEngine::end()
+{
+ gl_setclippingwindow(0, 0, device->width() - 1, device->height() - 1);
+ return QRasterPaintEngine::end();
+}
+//! [1]
+
+//! [2]
+void SvgalibPaintEngine::updateState()
+{
+ QRasterPaintEngineState *s = state();
+
+ if (s->dirty & DirtyTransform) {
+ matrix = s->matrix;
+ simpleMatrix = (matrix.m12() == 0 && matrix.m21() == 0);
+ }
+
+ if (s->dirty & DirtyPen) {
+ pen = s->pen;
+ simplePen = (pen.width() == 0 || pen.widthF() <= 1)
+ && (pen.style() == Qt::NoPen || pen.style() == Qt::SolidLine)
+ && (pen.color().alpha() == 255);
+ }
+
+ if (s->dirty & DirtyBrush) {
+ brush = s->brush;
+ simpleBrush = (brush.style() == Qt::SolidPattern
+ || brush.style() == Qt::NoBrush)
+ && (brush.color().alpha() == 255);
+ }
+
+ if (s->dirty & DirtyClipRegion)
+ setClip(s->clipRegion);
+
+ if (s->dirty & DirtyClipEnabled) {
+ clipEnabled = s->isClipEnabled();
+ updateClip();
+ }
+
+ if (s->dirty & DirtyClipPath) {
+ setClip(QRegion());
+ simpleClip = false;
+ }
+
+ if (s->dirty & DirtyCompositionMode) {
+ const QPainter::CompositionMode m = s->composition_mode;
+ sourceOver = (m == QPainter::CompositionMode_SourceOver);
+ }
+
+ if (s->dirty & DirtyOpacity)
+ opaque = (s->opacity == 256);
+
+ if (s->dirty & DirtyHints)
+ aliased = !(s->flags.antialiased);
+}
+//! [2]
+
+//! [3]
+void SvgalibPaintEngine::setClip(const QRegion &region)
+{
+ if (region.isEmpty())
+ clip = QRect(0, 0, device->width(), device->height());
+ else
+ clip = matrix.map(region) & QRect(0, 0, device->width(), device->height());
+ clipEnabled = true;
+ updateClip();
+}
+//! [3]
+
+//! [4]
+void SvgalibPaintEngine::updateClip()
+{
+ QRegion clipRegion = QRect(0, 0, device->width(), device->height());
+
+ if (!systemClip().isEmpty())
+ clipRegion &= systemClip();
+ if (clipEnabled)
+ clipRegion &= clip;
+
+ simpleClip = (clipRegion.rects().size() <= 1);
+
+ const QRect r = clipRegion.boundingRect();
+ gl_setclippingwindow(r.left(), r.top(),
+ r.x() + r.width(),
+ r.y() + r.height());
+}
+//! [4]
+
+//! [5]
+void SvgalibPaintEngine::drawRects(const QRect *rects, int rectCount)
+{
+ const bool canAccelerate = simplePen && simpleBrush && simpleMatrix
+ && simpleClip && opaque && aliased
+ && sourceOver;
+ if (!canAccelerate) {
+ QRasterPaintEngine::drawRects(rects, rectCount);
+ return;
+ }
+
+ for (int i = 0; i < rectCount; ++i) {
+ const QRect r = matrix.mapRect(rects[i]);
+ if (brush != Qt::NoBrush) {
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(),
+ brush.color().rgba());
+ }
+ if (pen != Qt::NoPen) {
+ const int c = pen.color().rgba();
+ gl_hline(r.left(), r.top(), r.right(), c);
+ gl_hline(r.left(), r.bottom(), r.right(), c);
+ gl_line(r.left(), r.top(), r.left(), r.bottom(), c);
+ gl_line(r.right(), r.top(), r.right(), r.bottom(), c);
+ }
+ }
+}
+//! [5]
diff --git a/examples/qws/svgalib/svgalibpaintengine.h b/examples/qws/svgalib/svgalibpaintengine.h
new file mode 100644
index 0000000000..d3d85ba7a8
--- /dev/null
+++ b/examples/qws/svgalib/svgalibpaintengine.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBPAINTENGINE_H
+#define SVGALIBPAINTENGINE_H
+
+//! [0]
+#include <private/qpaintengine_raster_p.h>
+
+class SvgalibPaintEngine : public QRasterPaintEngine
+{
+public:
+ SvgalibPaintEngine(QPaintDevice *device);
+ ~SvgalibPaintEngine();
+
+ bool begin(QPaintDevice *device);
+ bool end();
+ void updateState();
+ void drawRects(const QRect *rects, int rectCount);
+
+private:
+ void setClip(const QRegion &region);
+ void updateClip();
+
+ QPen pen;
+ bool simplePen;
+ QBrush brush;
+ bool simpleBrush;
+ QTransform matrix;
+ bool simpleMatrix;
+ QRegion clip;
+ bool clipEnabled;
+ bool simpleClip;
+ bool opaque;
+ bool aliased;
+ bool sourceOver;
+ QPaintDevice *device;
+};
+//! [0]
+
+#endif // SVGALIBPAINTENGINE_H
diff --git a/examples/qws/svgalib/svgalibplugin.cpp b/examples/qws/svgalib/svgalibplugin.cpp
new file mode 100644
index 0000000000..9be629e63b
--- /dev/null
+++ b/examples/qws/svgalib/svgalibplugin.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+
+#include <QScreenDriverPlugin>
+#include <QStringList>
+
+class SvgalibPlugin : public QScreenDriverPlugin
+{
+public:
+ SvgalibPlugin();
+
+ QStringList keys() const;
+ QScreen *create(const QString&, int displayId);
+};
+
+SvgalibPlugin::SvgalibPlugin()
+ : QScreenDriverPlugin()
+{
+}
+
+QStringList SvgalibPlugin::keys() const
+{
+ return (QStringList() << "svgalib");
+}
+
+QScreen* SvgalibPlugin::create(const QString& driver, int displayId)
+{
+ if (driver.toLower() != "svgalib")
+ return 0;
+
+ return new SvgalibScreen(displayId);
+}
+
+Q_EXPORT_STATIC_PLUGIN(Svgalib)
+Q_EXPORT_PLUGIN2(svgalibscreendriver, SvgalibPlugin)
diff --git a/examples/qws/svgalib/svgalibscreen.cpp b/examples/qws/svgalib/svgalibscreen.cpp
new file mode 100644
index 0000000000..163259178c
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.cpp
@@ -0,0 +1,353 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibscreen.h"
+#include "svgalibsurface.h"
+
+#include <QVector>
+#include <QApplication>
+#include <QColor>
+#include <QWidget>
+
+#include <math.h>
+
+static int getModeDepth(vga_modeinfo *mode)
+{
+ const int bits = int(log2(mode->colors));
+ if (bits == 24 && mode->bytesperpixel == 4)
+ return 32;
+ return bits;
+}
+
+//! [0]
+bool SvgalibScreen::connect(const QString &displaySpec)
+{
+ int mode = vga_getdefaultmode();
+ if (mode <= 0) {
+ qCritical("SvgalibScreen::connect(): invalid vga mode");
+ return false;
+ }
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+
+ QScreen::lstep = modeinfo->linewidth;
+ QScreen::dw = QScreen::w = modeinfo->width;
+ QScreen::dh = QScreen::h = modeinfo->height;
+ QScreen::d = getModeDepth(modeinfo);
+ QScreen::size = QScreen::lstep * dh;
+ QScreen::data = 0;
+
+ switch (depth()) {
+ case 32:
+ setPixelFormat(QImage::Format_ARGB32_Premultiplied);
+ break;
+ case 24:
+ setPixelFormat(QImage::Format_RGB888);
+ break;
+ case 16:
+ setPixelFormat(QImage::Format_RGB16);
+ break;
+ case 15:
+ setPixelFormat(QImage::Format_RGB555);
+ break;
+ default:
+ break;
+ }
+
+ const int dpi = 72;
+ QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
+ QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);
+
+ const QStringList args = displaySpec.split(QLatin1Char(':'),
+ QString::SkipEmptyParts);
+ grayscale = args.contains(QLatin1String("grayscale"), Qt::CaseInsensitive);
+
+ return true;
+}
+//! [0]
+
+void SvgalibScreen::initColorMap()
+{
+ const int numColors = vga_getcolors();
+ if (numColors == 2 || numColors > 256) {
+ screencols = 0;
+ return; // not a palette based mode
+ }
+
+ if (numColors == 16) {
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 16 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ screencols = 256; // XXX: takes advantage of optimization in alloc()
+ } else { // read in EGA palette
+ int r, g, b;
+ for (int i = 0; i < 16; ++i) {
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ }
+ screencols = 16;
+ }
+
+ return;
+ }
+
+ Q_ASSERT(numColors == 256);
+
+ if (grayscale) {
+ for (int i = 0; i < 256; ++i) {
+ const int c = i * 64 / 256;
+ vga_setpalette(i, c, c, c);
+ }
+ } else {
+ int i = 0;
+
+#if 0
+ // read in EGA palette
+ while (i < 16) {
+ int r, g, b;
+ vga_getpalette(i, &r, &g, &b);
+ screenclut[i] = qRgb(r, g, b);
+ ++i;
+ }
+ screencols = 16;
+#endif
+
+ // 6 * 6 * 6 color cube
+ for (int r = 0; r < 6; ++r) {
+ for (int g = 0; g < 6; ++g) {
+ for (int b = 0; b < 6; ++b) {
+ vga_setpalette(i, r * 64/6, g * 64/6, b * 64/6);
+ screenclut[i] = qRgb(r * 256/6, g * 256/6, b * 256/6);
+ ++i;
+ }
+ }
+ }
+ screencols = i;
+
+ while (i < 256) {
+ screenclut[i] = qRgb(0, 0, 0);
+ ++i;
+ }
+ }
+}
+
+//! [1]
+bool SvgalibScreen::initDevice()
+{
+ if (vga_init() != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to initialize svgalib");
+ return false;
+ }
+
+ int mode = vga_getdefaultmode();
+ if (vga_setmode(mode) == -1) {
+ qCritical("SvgalibScreen::initialize(): unable to set graphics mode");
+ return false;
+ }
+
+ if (gl_setcontextvga(mode) != 0) {
+ qCritical("SvgalibScreen::initDevice(): unable to set vga context");
+ return false;
+ }
+ context = gl_allocatecontext();
+ gl_getcontext(context);
+
+ vga_modeinfo *modeinfo = vga_getmodeinfo(mode);
+ if (modeinfo->flags & IS_LINEAR)
+ QScreen::data = vga_getgraphmem();
+
+ initColorMap();
+
+ QScreenCursor::initSoftwareCursor();
+ return true;
+}
+//! [1]
+
+//! [2]
+void SvgalibScreen::shutdownDevice()
+{
+ gl_freecontext(context);
+ vga_setmode(TEXT);
+}
+//! [2]
+
+//! [3]
+void SvgalibScreen::disconnect()
+{
+}
+//! [3]
+
+//! [4]
+void SvgalibScreen::solidFill(const QColor &color, const QRegion &reg)
+{
+ int c;
+ if (depth() == 4 || depth() == 8)
+ c = alloc(color.red(), color.green(), color.blue());
+ else
+ c = gl_rgbcolor(color.red(), color.green(), color.blue());
+
+ const QVector<QRect> rects = (reg & region()).rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_fillbox(r.left(), r.top(), r.width(), r.height(), c);
+ }
+}
+//! [4]
+
+void SvgalibScreen::blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 2;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint16 *s = reinterpret_cast<const quint16*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint16 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint16>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+void SvgalibScreen::blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region)
+{
+ const int imageStride = image.bytesPerLine() / 4;
+ const QVector<QRect> rects = region.rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i).translated(-topLeft);
+ int y = r.y();
+ const quint32 *s = reinterpret_cast<const quint32*>(image.scanLine(y));
+
+ while (y <= r.bottom()) {
+ int x1 = r.x();
+ while (x1 <= r.right()) {
+ const quint32 c = s[x1];
+ int x2 = x1;
+ // find span length
+ while ((x2+1 < r.right()) && (s[x2+1] == c))
+ ++x2;
+ gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(),
+ qt_colorConvert<quint8, quint32>(c, 0));
+ x1 = x2 + 1;
+ }
+ s += imageStride;
+ ++y;
+ }
+ }
+}
+
+//! [5]
+void SvgalibScreen::blit(const QImage &img, const QPoint &topLeft,
+ const QRegion &reg)
+{
+ if (depth() == 8) {
+ switch (img.format()) {
+ case QImage::Format_RGB16:
+ blit16To8(img, topLeft, reg);
+ return;
+ case QImage::Format_RGB32:
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ blit32To8(img, topLeft, reg);
+ return;
+ default:
+ break;
+ }
+ }
+
+ if (img.format() != pixelFormat()) {
+ if (base())
+ QScreen::blit(img, topLeft, reg);
+ return;
+ }
+
+ const QVector<QRect> rects = (reg & region()).rects();
+
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_putboxpart(r.x(), r.y(), r.width(), r.height(),
+ img.width(), img.height(),
+ static_cast<void*>(const_cast<uchar*>(img.bits())),
+ r.x() - topLeft.x(), r.y() - topLeft.y());
+ }
+}
+//! [5]
+
+//! [7]
+QWSWindowSurface* SvgalibScreen::createSurface(QWidget *widget) const
+{
+ if (base()) {
+ static int onScreenPaint = -1;
+ if (onScreenPaint == -1)
+ onScreenPaint = qgetenv("QT_ONSCREEN_PAINT").toInt();
+
+ if (onScreenPaint > 0 || widget->testAttribute(Qt::WA_PaintOnScreen))
+ return new SvgalibSurface(widget);
+ }
+ return QScreen::createSurface(widget);
+}
+//! [7]
+
+//! [8]
+QWSWindowSurface* SvgalibScreen::createSurface(const QString &key) const
+{
+ if (key == QLatin1String("svgalib"))
+ return new SvgalibSurface;
+ return QScreen::createSurface(key);
+}
+//! [8]
diff --git a/examples/qws/svgalib/svgalibscreen.h b/examples/qws/svgalib/svgalibscreen.h
new file mode 100644
index 0000000000..da3b05e103
--- /dev/null
+++ b/examples/qws/svgalib/svgalibscreen.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSCREEN_H
+#define SVGALIBSCREEN_H
+
+#include <QScreen>
+
+#include <vga.h>
+#include <vgagl.h>
+
+//! [0]
+class SvgalibScreen : public QScreen
+{
+public:
+ SvgalibScreen(int displayId) : QScreen(displayId) {}
+ ~SvgalibScreen() {}
+
+ bool connect(const QString &displaySpec);
+ bool initDevice();
+ void shutdownDevice();
+ void disconnect();
+
+ void setMode(int, int, int) {}
+ void blank(bool) {}
+
+ void blit(const QImage &img, const QPoint &topLeft, const QRegion &region);
+ void solidFill(const QColor &color, const QRegion &region);
+//! [0]
+
+ QWSWindowSurface* createSurface(QWidget *widget) const;
+ QWSWindowSurface* createSurface(const QString &key) const;
+
+//! [1]
+private:
+ void initColorMap();
+ void blit16To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+ void blit32To8(const QImage &image,
+ const QPoint &topLeft, const QRegion &region);
+
+ GraphicsContext *context;
+};
+//! [1]
+
+#endif // SVGALIBSCREEN_H
diff --git a/examples/qws/svgalib/svgalibsurface.cpp b/examples/qws/svgalib/svgalibsurface.cpp
new file mode 100644
index 0000000000..ad270a1783
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "svgalibsurface.h"
+#include "svgalibpaintdevice.h"
+
+#include <vgagl.h>
+
+SvgalibSurface::SvgalibSurface() : QWSWindowSurface(), pdevice(0)
+{
+ setSurfaceFlags(Opaque);
+}
+
+SvgalibSurface::SvgalibSurface(QWidget *w)
+ : QWSWindowSurface(w)
+{
+ setSurfaceFlags(Opaque);
+ pdevice = new SvgalibPaintDevice(w);
+}
+
+SvgalibSurface::~SvgalibSurface()
+{
+ delete pdevice;
+}
+
+void SvgalibSurface::setGeometry(const QRect &rect)
+{
+ QWSWindowSurface::setGeometry(rect);
+}
+
+QPoint SvgalibSurface::painterOffset() const
+{
+ return geometry().topLeft() + QWSWindowSurface::painterOffset();
+}
+
+//! [0]
+bool SvgalibSurface::scroll(const QRegion &region, int dx, int dy)
+{
+ const QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); ++i) {
+ const QRect r = rects.at(i);
+ gl_copybox(r.left(), r.top(), r.width(), r.height(),
+ r.left() + dx, r.top() + dy);
+ }
+
+ return true;
+}
+//! [0]
+
diff --git a/examples/qws/svgalib/svgalibsurface.h b/examples/qws/svgalib/svgalibsurface.h
new file mode 100644
index 0000000000..5c25e72521
--- /dev/null
+++ b/examples/qws/svgalib/svgalibsurface.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SVGALIBSURFACE_H
+#define SVGALIBSURFACE_H
+
+#include "svgalibpaintengine.h"
+#include "svgalibpaintdevice.h"
+#include <private/qwindowsurface_qws_p.h>
+
+class SvgalibPaintDevice;
+
+//! [0]
+class SvgalibSurface : public QWSWindowSurface
+{
+public:
+ SvgalibSurface();
+ SvgalibSurface(QWidget *w);
+ ~SvgalibSurface();
+
+ void setGeometry(const QRect &rect);
+ bool isValid() const { return true; }
+ bool scroll(const QRegion &region, int dx, int dy);
+ QString key() const { return QLatin1String("svgalib"); }
+
+ bool attach(const QByteArray &) { return true; }
+ void detach() {}
+
+ QImage image() const { return QImage(); }
+ QPaintDevice *paintDevice() { return pdevice; }
+ QPoint painterOffset() const;
+
+private:
+ SvgalibPaintDevice *pdevice;
+};
+//! [0]
+
+#endif // SVGALIBSURFACE_H
diff --git a/examples/richtext/README b/examples/richtext/README
new file mode 100644
index 0000000000..6697b237f5
--- /dev/null
+++ b/examples/richtext/README
@@ -0,0 +1,42 @@
+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.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/richtext/calendar/calendar.pro b/examples/richtext/calendar/calendar.pro
new file mode 100644
index 0000000000..5f53ed4cea
--- /dev/null
+++ b/examples/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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/richtext/calendar/main.cpp b/examples/richtext/calendar/main.cpp
new file mode 100644
index 0000000000..b23e883e24
--- /dev/null
+++ b/examples/richtext/calendar/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/calendar/mainwindow.cpp b/examples/richtext/calendar/mainwindow.cpp
new file mode 100644
index 0000000000..5117c03ae4
--- /dev/null
+++ b/examples/richtext/calendar/mainwindow.cpp
@@ -0,0 +1,214 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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);
+ fontSizeSpinBox->setValue(10);
+
+ 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]
+
+//! [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/richtext/calendar/mainwindow.h b/examples/richtext/calendar/mainwindow.h
new file mode 100644
index 0000000000..a9cf5216a7
--- /dev/null
+++ b/examples/richtext/calendar/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/orderform/detailsdialog.cpp b/examples/richtext/orderform/detailsdialog.cpp
new file mode 100644
index 0000000000..9aa8535c5b
--- /dev/null
+++ b/examples/richtext/orderform/detailsdialog.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/orderform/detailsdialog.h b/examples/richtext/orderform/detailsdialog.h
new file mode 100644
index 0000000000..dea3ea125e
--- /dev/null
+++ b/examples/richtext/orderform/detailsdialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/orderform/main.cpp b/examples/richtext/orderform/main.cpp
new file mode 100644
index 0000000000..3ad32b8e4e
--- /dev/null
+++ b/examples/richtext/orderform/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/orderform/mainwindow.cpp b/examples/richtext/orderform/mainwindow.cpp
new file mode 100644
index 0000000000..e08f3ba9d3
--- /dev/null
+++ b/examples/richtext/orderform/mainwindow.cpp
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/orderform/mainwindow.h b/examples/richtext/orderform/mainwindow.h
new file mode 100644
index 0000000000..af923f9760
--- /dev/null
+++ b/examples/richtext/orderform/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/orderform/orderform.pro b/examples/richtext/orderform/orderform.pro
new file mode 100644
index 0000000000..6a5041ba70
--- /dev/null
+++ b/examples/richtext/orderform/orderform.pro
@@ -0,0 +1,13 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/richtext/richtext.pro b/examples/richtext/richtext.pro
new file mode 100644
index 0000000000..aec3936833
--- /dev/null
+++ b/examples/richtext/richtext.pro
@@ -0,0 +1,14 @@
+TEMPLATE = subdirs
+SUBDIRS = calendar \
+ orderform \
+ syntaxhighlighter
+
+contains(QT_CONFIG, svg): SUBDIRS += textobject
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/richtext/syntaxhighlighter/highlighter.cpp b/examples/richtext/syntaxhighlighter/highlighter.cpp
new file mode 100644
index 0000000000..b51aa873a6
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/highlighter.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/syntaxhighlighter/highlighter.h b/examples/richtext/syntaxhighlighter/highlighter.h
new file mode 100644
index 0000000000..5bc69fc218
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/highlighter.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/syntaxhighlighter/main.cpp b/examples/richtext/syntaxhighlighter/main.cpp
new file mode 100644
index 0000000000..eecfb12bdc
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/syntaxhighlighter/mainwindow.cpp b/examples/richtext/syntaxhighlighter/mainwindow.cpp
new file mode 100644
index 0000000000..0d64489993
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/mainwindow.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/richtext/syntaxhighlighter/mainwindow.h b/examples/richtext/syntaxhighlighter/mainwindow.h
new file mode 100644
index 0000000000..cc7cf053f3
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/richtext/syntaxhighlighter/syntaxhighlighter.pro b/examples/richtext/syntaxhighlighter/syntaxhighlighter.pro
new file mode 100644
index 0000000000..5939134557
--- /dev/null
+++ b/examples/richtext/syntaxhighlighter/syntaxhighlighter.pro
@@ -0,0 +1,19 @@
+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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: {
+ addFiles.files = main.cpp mainwindow.cpp
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/scroller/graphicsview/graphicsview.pro b/examples/scroller/graphicsview/graphicsview.pro
new file mode 100644
index 0000000000..b0b8405293
--- /dev/null
+++ b/examples/scroller/graphicsview/graphicsview.pro
@@ -0,0 +1,8 @@
+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
diff --git a/examples/scroller/graphicsview/main.cpp b/examples/scroller/graphicsview/main.cpp
new file mode 100644
index 0000000000..738a824269
--- /dev/null
+++ b/examples/scroller/graphicsview/main.cpp
@@ -0,0 +1,295 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+#include <QtGui>
+
+#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);
+#ifdef Q_WS_S60
+ mw.showMaximized();
+#else
+ mw.show();
+#endif
+#ifdef Q_WS_MAC
+ mw.raise();
+#endif
+ return a.exec();
+}
+
+#include "main.moc"
diff --git a/examples/scroller/scroller.pro b/examples/scroller/scroller.pro
new file mode 100644
index 0000000000..bac3f26554
--- /dev/null
+++ b/examples/scroller/scroller.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += graphicsview
diff --git a/examples/sql/README b/examples/sql/README
new file mode 100644
index 0000000000..56b4b3e11f
--- /dev/null
+++ b/examples/sql/README
@@ -0,0 +1,40 @@
+Qt provides extensive database interoperability, with support for products
+from both open source and proprietary vendors.
+
+SQL support is integrated with Qt's model/view architecture, making it easier
+to provide GUI integration for your database applications.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/sql/cachedtable/cachedtable.pro b/examples/sql/cachedtable/cachedtable.pro
new file mode 100644
index 0000000000..c03e7213f4
--- /dev/null
+++ b/examples/sql/cachedtable/cachedtable.pro
@@ -0,0 +1,13 @@
+HEADERS = ../connection.h \
+ tableeditor.h
+SOURCES = main.cpp \
+ tableeditor.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/cachedtable
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS cachedtable.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/cachedtable
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/sql/cachedtable/main.cpp b/examples/sql/cachedtable/main.cpp
new file mode 100644
index 0000000000..26ddc42c54
--- /dev/null
+++ b/examples/sql/cachedtable/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "../connection.h"
+#include "tableeditor.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ if (!createConnection())
+ return 1;
+
+ TableEditor editor("person");
+ editor.show();
+ return editor.exec();
+}
+//! [0]
diff --git a/examples/sql/cachedtable/tableeditor.cpp b/examples/sql/cachedtable/tableeditor.cpp
new file mode 100644
index 0000000000..216f729d6f
--- /dev/null
+++ b/examples/sql/cachedtable/tableeditor.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSql>
+
+#include "tableeditor.h"
+
+//! [0]
+TableEditor::TableEditor(const QString &tableName, QWidget *parent)
+ : QDialog(parent)
+{
+ model = new QSqlTableModel(this);
+ model->setTable(tableName);
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+ model->select();
+
+ model->setHeaderData(0, Qt::Horizontal, tr("ID"));
+ model->setHeaderData(1, Qt::Horizontal, tr("First name"));
+ model->setHeaderData(2, Qt::Horizontal, tr("Last name"));
+
+//! [0] //! [1]
+ QTableView *view = new QTableView;
+ view->setModel(model);
+//! [1]
+
+//! [2]
+ submitButton = new QPushButton(tr("Submit"));
+ submitButton->setDefault(true);
+ revertButton = new QPushButton(tr("&Revert"));
+ quitButton = new QPushButton(tr("Quit"));
+
+ buttonBox = new QDialogButtonBox(Qt::Vertical);
+ buttonBox->addButton(submitButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(revertButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
+//! [2]
+
+//! [3]
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
+ connect(revertButton, SIGNAL(clicked()), model, SLOT(revertAll()));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+//! [3]
+
+//! [4]
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ mainLayout->addWidget(view);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Cached Table"));
+}
+//! [4]
+
+//! [5]
+void TableEditor::submit()
+{
+ model->database().transaction();
+ if (model->submitAll()) {
+ model->database().commit();
+ } else {
+ model->database().rollback();
+ QMessageBox::warning(this, tr("Cached Table"),
+ tr("The database reported an error: %1")
+ .arg(model->lastError().text()));
+ }
+}
+//! [5]
diff --git a/examples/sql/cachedtable/tableeditor.h b/examples/sql/cachedtable/tableeditor.h
new file mode 100644
index 0000000000..14d9986c63
--- /dev/null
+++ b/examples/sql/cachedtable/tableeditor.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABLEEDITOR_H
+#define TABLEEDITOR_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QPushButton;
+class QSqlTableModel;
+QT_END_NAMESPACE
+
+//! [0]
+class TableEditor : public QDialog
+{
+ Q_OBJECT
+
+public:
+ TableEditor(const QString &tableName, QWidget *parent = 0);
+
+private slots:
+ void submit();
+
+private:
+ QPushButton *submitButton;
+ QPushButton *revertButton;
+ QPushButton *quitButton;
+ QDialogButtonBox *buttonBox;
+ QSqlTableModel *model;
+};
+//! [0]
+
+#endif
diff --git a/examples/sql/connection.h b/examples/sql/connection.h
new file mode 100644
index 0000000000..cd2d1d44b6
--- /dev/null
+++ b/examples/sql/connection.h
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONNECTION_H
+#define CONNECTION_H
+
+#include <QMessageBox>
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QSqlQuery>
+
+/*
+ This file defines a helper function to open a connection to an
+ in-memory SQLITE database and to create a test table.
+
+ If you want to use another database, simply modify the code
+ below. All the examples in this directory use this function to
+ connect to a database.
+*/
+//! [0]
+static bool createConnection()
+{
+ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
+ db.setDatabaseName(":memory:");
+ if (!db.open()) {
+ QMessageBox::critical(0, qApp->tr("Cannot open database"),
+ qApp->tr("Unable to establish a database connection.\n"
+ "This example needs SQLite support. Please read "
+ "the Qt SQL driver documentation for information how "
+ "to build it.\n\n"
+ "Click Cancel to exit."), QMessageBox::Cancel);
+ return false;
+ }
+
+ QSqlQuery query;
+ query.exec("create table person (id int primary key, "
+ "firstname varchar(20), lastname varchar(20))");
+ query.exec("insert into person values(101, 'Danny', 'Young')");
+ query.exec("insert into person values(102, 'Christine', 'Holand')");
+ query.exec("insert into person values(103, 'Lars', 'Gordon')");
+ query.exec("insert into person values(104, 'Roberto', 'Robitaille')");
+ query.exec("insert into person values(105, 'Maria', 'Papadopoulos')");
+
+ query.exec("create table offices (id int primary key,"
+ "imagefile int,"
+ "location varchar(20),"
+ "country varchar(20),"
+ "description varchar(100))");
+ query.exec("insert into offices "
+ "values(0, 0, 'Oslo', 'Norway',"
+ "'Oslo is home to more than 500 000 citizens and has a "
+ "lot to offer.It has been called \"The city with the big "
+ "heart\" and this is a nickname we are happy to live up to.')");
+ query.exec("insert into offices "
+ "values(1, 1, 'Brisbane', 'Australia',"
+ "'Brisbane is the capital of Queensland, the Sunshine State, "
+ "where it is beautiful one day, perfect the next. "
+ "Brisbane is Australia''s 3rd largest city, being home "
+ "to almost 2 million people.')");
+ query.exec("insert into offices "
+ "values(2, 2, 'Redwood City', 'US',"
+ "'You find Redwood City in the heart of the Bay Area "
+ "just north of Silicon Valley. The largest nearby city is "
+ "San Jose which is the third largest city in California "
+ "and the 10th largest in the US.')");
+ query.exec("insert into offices "
+ "values(3, 3, 'Berlin', 'Germany',"
+ "'Berlin, the capital of Germany is dynamic, cosmopolitan "
+ "and creative, allowing for every kind of lifestyle. "
+ "East meets West in the metropolis at the heart of a "
+ "changing Europe.')");
+ query.exec("insert into offices "
+ "values(4, 4, 'Munich', 'Germany',"
+ "'Several technology companies are represented in Munich, "
+ "and the city is often called the \"Bavarian Silicon Valley\". "
+ "The exciting city is also filled with culture, "
+ "art and music. ')");
+ query.exec("insert into offices "
+ "values(5, 5, 'Beijing', 'China',"
+ "'Beijing as a capital city has more than 3000 years of "
+ "history. Today the city counts 12 million citizens, and "
+ "is the political, economic and cultural centre of China.')");
+
+ query.exec("create table images (locationid int, file varchar(20))");
+ query.exec("insert into images values(0, 'images/oslo.png')");
+ query.exec("insert into images values(1, 'images/brisbane.png')");
+ query.exec("insert into images values(2, 'images/redwood.png')");
+ query.exec("insert into images values(3, 'images/berlin.png')");
+ query.exec("insert into images values(4, 'images/munich.png')");
+ query.exec("insert into images values(5, 'images/beijing.png')");
+
+
+
+ return true;
+}
+//! [0]
+
+#endif
diff --git a/examples/sql/drilldown/drilldown.pro b/examples/sql/drilldown/drilldown.pro
new file mode 100644
index 0000000000..e3f05c2293
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.pro
@@ -0,0 +1,21 @@
+HEADERS = ../connection.h \
+ imageitem.h \
+ informationwindow.h \
+ view.h
+RESOURCES = drilldown.qrc
+SOURCES = imageitem.cpp \
+ informationwindow.cpp \
+ main.cpp \
+ view.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/drilldown
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS drilldown.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/drilldown
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C612
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/sql/drilldown/drilldown.qrc b/examples/sql/drilldown/drilldown.qrc
new file mode 100644
index 0000000000..d2fb12295b
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/oslo.png</file>
+ <file>images/brisbane.png</file>
+ <file>images/redwood.png</file>
+ <file>images/berlin.png</file>
+ <file>images/munich.png</file>
+ <file>images/beijing.png</file>
+ <file>logo.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/sql/drilldown/imageitem.cpp b/examples/sql/drilldown/imageitem.cpp
new file mode 100644
index 0000000000..52dff716d5
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "imageitem.h"
+
+//! [0]
+ImageItem::ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent,
+ QGraphicsScene *scene)
+ : QGraphicsPixmapItem(pixmap, parent, scene)
+{
+ recordId = id;
+ setAcceptsHoverEvents(true);
+
+ timeLine.setDuration(150);
+ timeLine.setFrameRange(0, 150);
+
+ connect(&timeLine, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int)));
+ connect(&timeLine, SIGNAL(finished()), this, SLOT(updateItemPosition()));
+
+ adjust();
+}
+//! [0]
+
+//! [1]
+void ImageItem::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
+{
+ timeLine.setDirection(QTimeLine::Forward);
+
+ if (z != 1.0) {
+ z = 1.0;
+ updateItemPosition();
+ }
+
+ if (timeLine.state() == QTimeLine::NotRunning)
+ timeLine.start();
+}
+//! [1]
+
+//! [2]
+void ImageItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
+{
+ timeLine.setDirection(QTimeLine::Backward);
+ if (z != 0.0)
+ z = 0.0;
+
+ if (timeLine.state() == QTimeLine::NotRunning)
+ timeLine.start();
+}
+//! [2]
+
+//! [3]
+void ImageItem::setFrame(int frame)
+{
+ adjust();
+ QPointF center = boundingRect().center();
+
+ translate(center.x(), center.y());
+ scale(1 + frame / 330.0, 1 + frame / 330.0);
+ translate(-center.x(), -center.y());
+}
+//! [3]
+
+//! [4]
+void ImageItem::adjust()
+{
+ QMatrix matrix;
+ matrix.scale(150/ boundingRect().width(), 120/ boundingRect().height());
+ setMatrix(matrix);
+}
+//! [4]
+
+//! [5]
+int ImageItem::id()
+{
+ return recordId;
+}
+//! [5]
+
+//! [6]
+void ImageItem::updateItemPosition()
+{
+ setZValue(z);
+}
+//! [6]
+
+
diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h
new file mode 100644
index 0000000000..13d99c3846
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGEITEM_H
+#define IMAGEITEM_H
+
+#include <QtCore>
+#include <QtGui/QGraphicsPixmapItem>
+
+//! [0]
+class ImageItem : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+
+public:
+ ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = 0,
+ QGraphicsScene *scene = 0);
+
+ void adjust();
+ int id();
+
+protected:
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+
+private slots:
+ void setFrame(int frame);
+ void updateItemPosition();
+
+private:
+ QTimeLine timeLine;
+ int recordId;
+ double z;
+};
+//! [0]
+
+#endif
diff --git a/examples/sql/drilldown/images/beijing.png b/examples/sql/drilldown/images/beijing.png
new file mode 100644
index 0000000000..45df148506
--- /dev/null
+++ b/examples/sql/drilldown/images/beijing.png
Binary files differ
diff --git a/examples/sql/drilldown/images/berlin.png b/examples/sql/drilldown/images/berlin.png
new file mode 100644
index 0000000000..ead62f0421
--- /dev/null
+++ b/examples/sql/drilldown/images/berlin.png
Binary files differ
diff --git a/examples/sql/drilldown/images/brisbane.png b/examples/sql/drilldown/images/brisbane.png
new file mode 100644
index 0000000000..04fff57f9c
--- /dev/null
+++ b/examples/sql/drilldown/images/brisbane.png
Binary files differ
diff --git a/examples/sql/drilldown/images/munich.png b/examples/sql/drilldown/images/munich.png
new file mode 100644
index 0000000000..741eb77b8d
--- /dev/null
+++ b/examples/sql/drilldown/images/munich.png
Binary files differ
diff --git a/examples/sql/drilldown/images/oslo.png b/examples/sql/drilldown/images/oslo.png
new file mode 100644
index 0000000000..02fa25e5a0
--- /dev/null
+++ b/examples/sql/drilldown/images/oslo.png
Binary files differ
diff --git a/examples/sql/drilldown/images/redwood.png b/examples/sql/drilldown/images/redwood.png
new file mode 100644
index 0000000000..f39ac06578
--- /dev/null
+++ b/examples/sql/drilldown/images/redwood.png
Binary files differ
diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp
new file mode 100644
index 0000000000..3f43a5901f
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "informationwindow.h"
+
+//! [0]
+InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices,
+ QWidget *parent)
+ : QDialog(parent)
+{
+//! [0] //! [1]
+ QLabel *locationLabel = new QLabel(tr("Location: "));
+ QLabel *countryLabel = new QLabel(tr("Country: "));
+ QLabel *descriptionLabel = new QLabel(tr("Description: "));
+ QLabel *imageFileLabel = new QLabel(tr("Image file: "));
+
+ createButtons();
+
+ locationText = new QLabel;
+ countryText = new QLabel;
+ descriptionEditor = new QTextEdit;
+//! [1]
+
+//! [2]
+ imageFileEditor = new QComboBox;
+ imageFileEditor->setModel(offices->relationModel(1));
+ imageFileEditor->setModelColumn(offices->relationModel(1)->fieldIndex("file"));
+//! [2]
+
+//! [3]
+ mapper = new QDataWidgetMapper(this);
+ mapper->setModel(offices);
+ mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
+ mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));
+ mapper->addMapping(imageFileEditor, 1);
+ mapper->addMapping(locationText, 2, "text");
+ mapper->addMapping(countryText, 3, "text");
+ mapper->addMapping(descriptionEditor, 4);
+ mapper->setCurrentIndex(id);
+//! [3]
+
+//! [4]
+ connect(descriptionEditor, SIGNAL(textChanged()),
+ this, SLOT(enableButtons()));
+ connect(imageFileEditor, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(enableButtons()));
+
+ QFormLayout *formLayout = new QFormLayout;
+ formLayout->addRow(locationLabel, locationText);
+ formLayout->addRow(countryLabel, countryText);
+ formLayout->addRow(imageFileLabel, imageFileEditor);
+ formLayout->addRow(descriptionLabel, descriptionEditor);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addLayout(formLayout);
+ layout->addWidget(buttonBox);
+ setLayout(layout);
+
+ locationId = id;
+ displayedImage = imageFileEditor->currentText();
+
+ setWindowFlags(Qt::Window);
+ enableButtons(false);
+ setWindowTitle(tr("Office: %1").arg(locationText->text()));
+}
+//! [4]
+
+//! [5]
+int InformationWindow::id()
+{
+ return locationId;
+}
+//! [5]
+
+//! [6]
+void InformationWindow::revert()
+{
+ mapper->revert();
+ enableButtons(false);
+}
+//! [6]
+
+//! [7]
+void InformationWindow::submit()
+{
+ QString newImage(imageFileEditor->currentText());
+
+ if (displayedImage != newImage) {
+ displayedImage = newImage;
+ emit imageChanged(locationId, newImage);
+ }
+
+ mapper->submit();
+ mapper->setCurrentIndex(locationId);
+
+ enableButtons(false);
+}
+//! [7]
+
+//! [8]
+void InformationWindow::createButtons()
+{
+ closeButton = new QPushButton(tr("&Close"));
+ revertButton = new QPushButton(tr("&Revert"));
+ submitButton = new QPushButton(tr("&Submit"));
+
+ closeButton->setDefault(true);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(revertButton, SIGNAL(clicked()), this, SLOT(revert()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
+//! [8]
+
+//! [9]
+ buttonBox = new QDialogButtonBox(this);
+ buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
+ buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
+ buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
+}
+//! [9]
+
+//! [10]
+void InformationWindow::enableButtons(bool enable)
+{
+ revertButton->setEnabled(enable);
+ submitButton->setEnabled(enable);
+}
+//! [10]
+
+
diff --git a/examples/sql/drilldown/informationwindow.h b/examples/sql/drilldown/informationwindow.h
new file mode 100644
index 0000000000..354823f152
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef INFORMATIONWINDOW_H
+#define INFORMATIONWINDOW_H
+
+#include <QtGui>
+#include <QtSql>
+
+//! [0]
+class InformationWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ InformationWindow(int id, QSqlRelationalTableModel *offices,
+ QWidget *parent = 0);
+
+ int id();
+
+signals:
+ void imageChanged(int id, const QString &fileName);
+//! [0]
+
+//! [1]
+private slots:
+ void revert();
+ void submit();
+ void enableButtons(bool enable = true);
+//! [1]
+
+//! [2]
+private:
+ void createButtons();
+
+ int locationId;
+ QString displayedImage;
+
+ QComboBox *imageFileEditor;
+ QLabel *locationText;
+ QLabel *countryText;
+ QTextEdit *descriptionEditor;
+
+ QPushButton *closeButton;
+ QPushButton *submitButton;
+ QPushButton *revertButton;
+ QDialogButtonBox *buttonBox;
+
+ QDataWidgetMapper *mapper;
+};
+//! [2]
+
+#endif
diff --git a/examples/sql/drilldown/logo.png b/examples/sql/drilldown/logo.png
new file mode 100644
index 0000000000..4b1d235488
--- /dev/null
+++ b/examples/sql/drilldown/logo.png
Binary files differ
diff --git a/examples/sql/drilldown/main.cpp b/examples/sql/drilldown/main.cpp
new file mode 100644
index 0000000000..e3c8fa7cce
--- /dev/null
+++ b/examples/sql/drilldown/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+
+#include "../connection.h"
+#include "view.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(drilldown);
+
+ QApplication app(argc, argv);
+
+ if (!createConnection())
+ return 1;
+
+ View view("offices", "images");
+#ifndef Q_OS_SYMBIAN
+ view.show();
+#else
+ view.showFullScreen();
+#endif
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
new file mode 100644
index 0000000000..68fe06a8e2
--- /dev/null
+++ b/examples/sql/drilldown/view.cpp
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "informationwindow.h"
+#include "imageitem.h"
+#include "view.h"
+
+//! [0]
+View::View(const QString &offices, const QString &images, QWidget *parent)
+ : QGraphicsView(parent)
+{
+ officeTable = new QSqlRelationalTableModel(this);
+ officeTable->setTable(offices);
+ officeTable->setRelation(1, QSqlRelation(images, "locationid", "file"));
+ officeTable->select();
+//! [0]
+
+//! [1]
+ scene = new QGraphicsScene(this);
+ scene->setSceneRect(0, 0, 465, 615);
+ setScene(scene);
+
+ addItems();
+
+ QGraphicsPixmapItem *logo = scene->addPixmap(QPixmap(":/logo.png"));
+ logo->setPos(30, 515);
+
+#ifndef Q_OS_SYMBIAN
+ setMinimumSize(470, 620);
+ setMaximumSize(470, 620);
+#else
+ setDragMode(QGraphicsView::ScrollHandDrag);
+#endif
+
+ setWindowTitle(tr("Offices World Wide"));
+}
+//! [1]
+
+//! [3]
+void View::addItems()
+{
+ int officeCount = officeTable->rowCount();
+
+ int imageOffset = 150;
+ int leftMargin = 70;
+ int topMargin = 40;
+
+ for (int i = 0; i < officeCount; i++) {
+ ImageItem *image;
+ QGraphicsTextItem *label;
+ QSqlRecord record = officeTable->record(i);
+
+ int id = record.value("id").toInt();
+ QString file = record.value("file").toString();
+ QString location = record.value("location").toString();
+
+ int columnOffset = ((i / 3) * 37);
+ int x = ((i / 3) * imageOffset) + leftMargin + columnOffset;
+ int y = ((i % 3) * imageOffset) + topMargin;
+
+ image = new ImageItem(id, QPixmap(":/" + file));
+ image->setData(0, i);
+ image->setPos(x, y);
+ scene->addItem(image);
+
+ label = scene->addText(location);
+ QPointF labelOffset((150 - label->boundingRect().width()) / 2, 120.0);
+ label->setPos(QPointF(x, y) + labelOffset);
+ }
+}
+//! [3]
+
+//! [5]
+void View::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (QGraphicsItem *item = itemAt(event->pos())) {
+ if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item))
+ showInformation(image);
+ }
+ QGraphicsView::mouseReleaseEvent(event);
+}
+//! [5]
+
+//! [6]
+void View::showInformation(ImageItem *image)
+{
+ int id = image->id();
+ if (id < 0 || id >= officeTable->rowCount())
+ return;
+
+ InformationWindow *window = findWindow(id);
+ if (window && window->isVisible()) {
+ window->raise();
+ window->activateWindow();
+ } else if (window && !window->isVisible()) {
+#ifndef Q_OS_SYMBIAN
+ window->show();
+#else
+ window->showMaximized();
+#endif
+ } else {
+ InformationWindow *window;
+ window = new InformationWindow(id, officeTable, this);
+
+ connect(window, SIGNAL(imageChanged(int,QString)),
+ this, SLOT(updateImage(int,QString)));
+
+#ifndef Q_OS_SYMBIAN
+ window->move(pos() + QPoint(20, 40));
+ window->show();
+#else
+ window->showMaximized();
+#endif
+ informationWindows.append(window);
+ }
+}
+//! [6]
+
+//! [7]
+void View::updateImage(int id, const QString &fileName)
+{
+ QList<QGraphicsItem *> items = scene->items();
+
+ while(!items.empty()) {
+ QGraphicsItem *item = items.takeFirst();
+
+ if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item)) {
+ if (image->id() == id){
+ image->setPixmap(QPixmap(":/" +fileName));
+ image->adjust();
+ break;
+ }
+ }
+ }
+}
+//! [7]
+
+//! [8]
+InformationWindow* View::findWindow(int id)
+{
+ QList<InformationWindow*>::iterator i, beginning, end;
+
+ beginning = informationWindows.begin();
+ end = informationWindows.end();
+
+ for (i = beginning; i != end; ++i) {
+ InformationWindow *window = (*i);
+ if (window && (window->id() == id))
+ return window;
+ }
+ return 0;
+}
+//! [8]
+
diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h
new file mode 100644
index 0000000000..3efe6bb8ce
--- /dev/null
+++ b/examples/sql/drilldown/view.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIEW_H
+#define VIEW_H
+
+#include <QtGui>
+#include <QtSql>
+
+class ImageItem;
+class InformationWindow;
+
+//! [0]
+class View : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ View(const QString &offices, const QString &images, QWidget *parent = 0);
+
+protected:
+ void mouseReleaseEvent(QMouseEvent *event);
+//! [0]
+
+//! [1]
+private slots:
+ void updateImage(int id, const QString &fileName);
+//! [1]
+
+//! [2]
+private:
+ void addItems();
+ InformationWindow* findWindow(int id);
+ void showInformation(ImageItem *image);
+
+ QGraphicsScene *scene;
+ QList<InformationWindow *> informationWindows;
+//! [2] //! [3]
+ QSqlRelationalTableModel *officeTable;
+};
+//! [3]
+
+#endif
diff --git a/examples/sql/masterdetail/albumdetails.xml b/examples/sql/masterdetail/albumdetails.xml
new file mode 100644
index 0000000000..aacbdac81d
--- /dev/null
+++ b/examples/sql/masterdetail/albumdetails.xml
@@ -0,0 +1,98 @@
+ <archive>
+ <album id="1" >
+ <track number="01" >Humming one of your songs</track>
+ <track number="02" >Are they saying goodbye</track>
+ <track number="03" >On off</track>
+ <track number="04" >I shot my heart</track>
+ <track number="05" >Drowning in Those Eyes</track>
+ <track number="06" >So you did it again</track>
+ <track number="07" >One more time</track>
+ <track number="08" >Headphone silence</track>
+ <track number="09" >What I want</track>
+ <track number="10" >Sleeping by the Fyris River</track>
+ <track number="11" >Wooden Body</track>
+ <track number="12" >Humming one of your songs (encore)</track>
+ </album>
+ <album id="2" >
+ <track number="01" >To let myself go</track>
+ <track number="02" >Rubber and Soul</track>
+ <track number="03" >Balloon ranger</track>
+ <track number="04" >My lover will go</track>
+ <track number="05" >Temporary dive</track>
+ <track number="06" >Laid in earth</track>
+ <track number="07" >This voice</track>
+ <track number="08" >Where friend rhymes with end</track>
+ <track number="09" >Song No.6 feat Ron Sexsmith</track>
+ <track number="10" >The Fight Song</track>
+ </album>
+ <album id="3" >
+ <track number="01" >From Grace</track>
+ <track number="02" >All's not last</track>
+ <track number="03" >That Great October Sound</track>
+ <track number="04" >Life Here Is Gold</track>
+ <track number="05" >Tomorrow Stays The Same</track>
+ <track number="06" >Postulate</track>
+ <track number="07" >Adelaide</track>
+ <track number="08" >John Wayne</track>
+ <track number="09" >Love's Lost</track>
+ <track number="10" >Dreamweaver</track>
+ <track number="11" >Outro</track>
+ </album>
+ <album id="4" >
+ <track number="01" >Rain down on me</track>
+ <track number="02" >Cecilia</track>
+ <track number="03" >Make a mess of yourself</track>
+ <track number="04" >Pale green eyes</track>
+ <track number="05" >Either way I'm gone</track>
+ <track number="06" >Honey</track>
+ <track number="07" >Rise in shame</track>
+ <track number="08" >Stray dogs</track>
+ <track number="09" >The willow</track>
+ <track number="10" >Stay home</track>
+ <track number="11" >Outro</track>
+ </album>
+ <album id="5" >
+ </album>
+ <album id="6" >
+ <track number="01" >Kontroll på kontinentet</track>
+ <track number="02" >Ompa til du dør</track>
+ <track number="03" >Bøn fra helvete</track>
+ <track number="04" >170</track>
+ <track number="05" >Rullett</track>
+ <track number="06" >Dr. Mowinckel</track>
+ <track number="07" >Fra sjåfør til passasjer</track>
+ <track number="08" >Resistansen</track>
+ <track number="09" >Dekk bord</track>
+ <track number="10" >Bak et halleluja</track>
+ <track number="11" >Bris</track>
+ <track number="12" >Mr. Kaizer, hans Constanze og meg</track>
+ </album>
+ <album id="7" >
+ <track number="01" >Di grind</track>
+ <track number="02" >Hevnervals</track>
+ <track number="03" >Evig pint</track>
+ <track number="04" >De involverte</track>
+ <track number="05" >Djevelens orkester</track>
+ <track number="06" >Container</track>
+ <track number="07" >Naade</track>
+ <track number="08" >Min kvite russer</track>
+ <track number="09" >Veterans klage</track>
+ <track number="10" >Til depotet</track>
+ <track number="11" >Salt og pepper</track>
+ <track number="12" >Drøm Hardt (Requiem Part I)</track>
+ </album>
+ <album id="8" >
+ <track number="01" >KGB</track>
+ <track number="02" >Maestro</track>
+ <track number="03" >Knekker deg til sist</track>
+ <track number="04" >Senor Flamingos Adieu</track>
+ <track number="05" >Blitzregn baby</track>
+ <track number="06" >Dieter Meyers Inst.</track>
+ <track number="07" >Christiania</track>
+ <track number="08" >Delikatessen</track>
+ <track number="09" >Jævel av en tango</track>
+ <track number="10" >Papa har lov</track>
+ <track number="11" >Auksjon (i Dieter Meyers hall)</track>
+ <track number="12" >På ditt skift</track>
+ </album>
+ </archive>
diff --git a/examples/sql/masterdetail/database.h b/examples/sql/masterdetail/database.h
new file mode 100644
index 0000000000..ab9a8ff2d6
--- /dev/null
+++ b/examples/sql/masterdetail/database.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DATABASE_H
+#define DATABASE_H
+
+#include <QMessageBox>
+#include <QSqlDatabase>
+#include <QSqlError>
+#include <QSqlQuery>
+
+static bool createConnection()
+{
+ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
+ db.setDatabaseName(":memory:");
+ if (!db.open()) {
+ QMessageBox::critical(0, qApp->tr("Cannot open database"),
+ qApp->tr("Unable to establish a database connection.\n"
+ "This example needs SQLite support. Please read "
+ "the Qt SQL driver documentation for information how "
+ "to build it.\n\n"
+ "Click Cancel to exit."), QMessageBox::Cancel);
+ return false;
+ }
+
+ QSqlQuery query;
+
+ query.exec("create table artists (id int primary key, "
+ "artist varchar(40), "
+ "albumcount int)");
+
+ query.exec("insert into artists values(0, '<all>', 0)");
+ query.exec("insert into artists values(1, 'Ane Brun', 2)");
+ query.exec("insert into artists values(2, 'Thomas Dybdahl', 3)");
+ query.exec("insert into artists values(3, 'Kaizers Orchestra', 3)");
+
+ query.exec("create table albums (albumid int primary key, "
+ "title varchar(50), "
+ "artistid int, "
+ "year int)");
+
+ query.exec("insert into albums values(1, 'Spending Time With Morgan', 1, "
+ "2003)");
+ query.exec("insert into albums values(2, 'A Temporary Dive', 1, 2005)");
+ query.exec("insert into albums values(3, '...The Great October Sound', 2, "
+ "2002)");
+ query.exec("insert into albums values(4, 'Stray Dogs', 2, 2003)");
+ query.exec("insert into albums values(5, "
+ "'One day you`ll dance for me, New York City', 2, 2004)");
+ query.exec("insert into albums values(6, 'Ompa Til Du D\xf8r', 3, 2001)");
+ query.exec("insert into albums values(7, 'Evig Pint', 3, 2002)");
+ query.exec("insert into albums values(8, 'Maestro', 3, 2005)");
+
+ return true;
+}
+
+#endif
+
+
diff --git a/examples/sql/masterdetail/dialog.cpp b/examples/sql/masterdetail/dialog.cpp
new file mode 100644
index 0000000000..9dc0fe14e3
--- /dev/null
+++ b/examples/sql/masterdetail/dialog.cpp
@@ -0,0 +1,282 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "dialog.h"
+
+int uniqueAlbumId;
+int uniqueArtistId;
+
+Dialog::Dialog(QSqlRelationalTableModel *albums, QDomDocument details,
+ QFile *output, QWidget *parent)
+ : QDialog(parent)
+{
+ model = albums;
+ albumDetails = details;
+ outputFile = output;
+
+ QGroupBox *inputWidgetBox = createInputWidgets();
+ QDialogButtonBox *buttonBox = createButtons();
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(inputWidgetBox);
+ layout->addWidget(buttonBox);
+ setLayout(layout);
+
+ setWindowTitle(tr("Add Album"));
+}
+
+void Dialog::submit()
+{
+ QString artist = artistEditor->text();
+ QString title = titleEditor->text();
+
+ if (artist.isEmpty() || title.isEmpty()) {
+ QString message(tr("Please provide both the name of the artist "
+ "and the title of the album."));
+ QMessageBox::information(this, tr("Add Album"), message);
+ } else {
+ int artistId = findArtistId(artist);
+ int albumId = addNewAlbum(title, artistId);
+
+ QStringList tracks;
+ tracks = tracksEditor->text().split(',', QString::SkipEmptyParts);
+ addTracks(albumId, tracks);
+
+ increaseAlbumCount(indexOfArtist(artist));
+ accept();
+ }
+}
+
+int Dialog::findArtistId(const QString &artist)
+{
+ QSqlTableModel *artistModel = model->relationModel(2);
+ int row = 0;
+
+ while (row < artistModel->rowCount()) {
+ QSqlRecord record = artistModel->record(row);
+ if (record.value("artist") == artist)
+ return record.value("id").toInt();
+ else
+ row++;
+ }
+ return addNewArtist(artist);
+}
+
+
+int Dialog::addNewArtist(const QString &name)
+{
+ QSqlTableModel *artistModel = model->relationModel(2);
+ QSqlRecord record;
+
+ int id = generateArtistId();
+
+ QSqlField f1("id", QVariant::Int);
+ QSqlField f2("artist", QVariant::String);
+ QSqlField f3("albumcount", QVariant::Int);
+
+ f1.setValue(QVariant(id));
+ f2.setValue(QVariant(name));
+ f3.setValue(QVariant(0));
+ record.append(f1);
+ record.append(f2);
+ record.append(f3);
+
+ artistModel->insertRecord(-1, record);
+ return id;
+}
+
+int Dialog::addNewAlbum(const QString &title, int artistId)
+{
+ int id = generateAlbumId();
+ QSqlRecord record;
+
+ QSqlField f1("albumid", QVariant::Int);
+ QSqlField f2("title", QVariant::String);
+ QSqlField f3("artistid", QVariant::Int);
+ QSqlField f4("year", QVariant::Int);
+
+ f1.setValue(QVariant(id));
+ f2.setValue(QVariant(title));
+ f3.setValue(QVariant(artistId));
+ f4.setValue(QVariant(yearEditor->value()));
+ record.append(f1);
+ record.append(f2);
+ record.append(f3);
+ record.append(f4);
+
+ model->insertRecord(-1, record);
+ return id;
+}
+
+void Dialog::addTracks(int albumId, QStringList tracks)
+{
+ QDomElement albumNode = albumDetails.createElement("album");
+ albumNode.setAttribute("id", albumId);
+
+ for (int i = 0; i < tracks.count(); i++) {
+ QString trackNumber = QString::number(i);
+ if (i < 10)
+ trackNumber.prepend("0");
+
+ QDomText textNode = albumDetails.createTextNode(tracks.at(i));
+
+ QDomElement trackNode = albumDetails.createElement("track");
+ trackNode.setAttribute("number", trackNumber);
+ trackNode.appendChild(textNode);
+
+ albumNode.appendChild(trackNode);
+ }
+
+ QDomNodeList archive = albumDetails.elementsByTagName("archive");
+ archive.item(0).appendChild(albumNode);
+
+/*
+ The following code is commented out since the example uses an in
+ memory database, i.e., altering the XML file will bring the data
+ out of sync.
+
+ if (!outputFile->open(QIODevice::WriteOnly)) {
+ return;
+ } else {
+ QTextStream stream(outputFile);
+ archive.item(0).save(stream, 4);
+ outputFile->close();
+ }
+*/
+}
+
+void Dialog::increaseAlbumCount(QModelIndex artistIndex)
+{
+ QSqlTableModel *artistModel = model->relationModel(2);
+
+ QModelIndex albumCountIndex;
+ albumCountIndex = artistIndex.sibling(artistIndex.row(), 2);
+
+ int albumCount = albumCountIndex.data().toInt();
+ artistModel->setData(albumCountIndex, QVariant(albumCount + 1));
+}
+
+
+void Dialog::revert()
+{
+ artistEditor->clear();
+ titleEditor->clear();
+ yearEditor->setValue(QDate::currentDate().year());
+ tracksEditor->clear();
+}
+
+QGroupBox *Dialog::createInputWidgets()
+{
+ QGroupBox *box = new QGroupBox(tr("Add Album"));
+
+ QLabel *artistLabel = new QLabel(tr("Artist:"));
+ QLabel *titleLabel = new QLabel(tr("Title:"));
+ QLabel *yearLabel = new QLabel(tr("Year:"));
+ QLabel *tracksLabel = new QLabel(tr("Tracks (separated by comma):"));
+
+ artistEditor = new QLineEdit;
+ titleEditor = new QLineEdit;
+
+ yearEditor = new QSpinBox;
+ yearEditor->setMinimum(1900);
+ yearEditor->setMaximum(QDate::currentDate().year());
+ yearEditor->setValue(yearEditor->maximum());
+ yearEditor->setReadOnly(false);
+
+ tracksEditor = new QLineEdit;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(artistLabel, 0, 0);
+ layout->addWidget(artistEditor, 0, 1);
+ layout->addWidget(titleLabel, 1, 0);
+ layout->addWidget(titleEditor, 1, 1);
+ layout->addWidget(yearLabel, 2, 0);
+ layout->addWidget(yearEditor, 2, 1);
+ layout->addWidget(tracksLabel, 3, 0, 1, 2);
+ layout->addWidget(tracksEditor, 4, 0, 1, 2);
+ box->setLayout(layout);
+
+ return box;
+}
+
+QDialogButtonBox *Dialog::createButtons()
+{
+ QPushButton *closeButton = new QPushButton(tr("&Close"));
+ QPushButton *revertButton = new QPushButton(tr("&Revert"));
+ QPushButton *submitButton = new QPushButton(tr("&Submit"));
+
+ closeButton->setDefault(true);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(revertButton, SIGNAL(clicked()), this, SLOT(revert()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
+
+ QDialogButtonBox *buttonBox = new QDialogButtonBox;
+ buttonBox->addButton(submitButton, QDialogButtonBox::ResetRole);
+ buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
+ buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
+
+ return buttonBox;
+}
+
+QModelIndex Dialog::indexOfArtist(const QString &artist)
+{
+ QSqlTableModel *artistModel = model->relationModel(2);
+
+ for (int i = 0; i < artistModel->rowCount(); i++) {
+ QSqlRecord record = artistModel->record(i);
+ if (record.value("artist") == artist)
+ return artistModel->index(i, 1);
+ }
+
+ return QModelIndex();
+}
+
+int Dialog::generateArtistId()
+{
+ uniqueArtistId += 1;
+ return uniqueArtistId;
+}
+
+int Dialog::generateAlbumId()
+{
+ uniqueAlbumId += 1;
+ return uniqueAlbumId;
+}
diff --git a/examples/sql/masterdetail/dialog.h b/examples/sql/masterdetail/dialog.h
new file mode 100644
index 0000000000..5495a115b3
--- /dev/null
+++ b/examples/sql/masterdetail/dialog.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QtGui>
+#include <QtSql>
+#include <QtXml>
+
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog(QSqlRelationalTableModel *albums, QDomDocument details,
+ QFile *output, QWidget *parent = 0);
+
+private slots:
+ void revert();
+ void submit();
+
+private:
+ int addNewAlbum(const QString &title, int artistId);
+ int addNewArtist(const QString &name);
+ void addTracks(int albumId, QStringList tracks);
+ QDialogButtonBox *createButtons();
+ QGroupBox *createInputWidgets();
+ int findArtistId(const QString &artist);
+ int generateAlbumId();
+ int generateArtistId();
+ void increaseAlbumCount(QModelIndex artistIndex);
+ QModelIndex indexOfArtist(const QString &artist);
+
+ QSqlRelationalTableModel *model;
+ QDomDocument albumDetails;
+ QFile *outputFile;
+
+ QLineEdit *artistEditor;
+ QLineEdit *titleEditor;
+ QSpinBox *yearEditor;
+ QLineEdit *tracksEditor;
+};
+
+#endif
diff --git a/examples/sql/masterdetail/images/icon.png b/examples/sql/masterdetail/images/icon.png
new file mode 100644
index 0000000000..31f68b8eb5
--- /dev/null
+++ b/examples/sql/masterdetail/images/icon.png
Binary files differ
diff --git a/examples/sql/masterdetail/images/image.png b/examples/sql/masterdetail/images/image.png
new file mode 100644
index 0000000000..1d7803746b
--- /dev/null
+++ b/examples/sql/masterdetail/images/image.png
Binary files differ
diff --git a/examples/sql/masterdetail/main.cpp b/examples/sql/masterdetail/main.cpp
new file mode 100644
index 0000000000..fe3dd9db50
--- /dev/null
+++ b/examples/sql/masterdetail/main.cpp
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "database.h"
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(masterdetail);
+
+ QApplication app(argc, argv);
+
+ if (!createConnection())
+ return 1;
+
+ QFile *albumDetails = new QFile("albumdetails.xml");
+ MainWindow window("artists", "albums", albumDetails);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/sql/masterdetail/mainwindow.cpp b/examples/sql/masterdetail/mainwindow.cpp
new file mode 100644
index 0000000000..24771bad09
--- /dev/null
+++ b/examples/sql/masterdetail/mainwindow.cpp
@@ -0,0 +1,429 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "dialog.h"
+
+#include <QtGui>
+#include <QtSql>
+#include <QtXml>
+
+extern int uniqueAlbumId;
+extern int uniqueArtistId;
+
+MainWindow::MainWindow(const QString &artistTable, const QString &albumTable,
+ QFile *albumDetails, QWidget *parent)
+ : QMainWindow(parent)
+{
+ file = albumDetails;
+ readAlbumData();
+
+ model = new QSqlRelationalTableModel(this);
+ model->setTable(albumTable);
+ model->setRelation(2, QSqlRelation(artistTable, "id", "artist"));
+ model->select();
+
+ QGroupBox *artists = createArtistGroupBox();
+ QGroupBox *albums = createAlbumGroupBox();
+ QGroupBox *details = createDetailsGroupBox();
+
+ artistView->setCurrentIndex(0);
+ uniqueAlbumId = model->rowCount();
+ uniqueArtistId = artistView->count();
+
+ connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
+ this, SLOT(updateHeader(QModelIndex,int,int)));
+ connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ this, SLOT(updateHeader(QModelIndex,int,int)));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(artists, 0, 0);
+ layout->addWidget(albums, 1, 0);
+ layout->addWidget(details, 0, 1, 2, 1);
+ layout->setColumnStretch(1, 1);
+ layout->setColumnMinimumWidth(0, 500);
+
+ QWidget *widget = new QWidget;
+ widget->setLayout(layout);
+ setCentralWidget(widget);
+ createMenuBar();
+
+ showImageLabel();
+ resize(850, 400);
+ setWindowTitle(tr("Music Archive"));
+}
+
+void MainWindow::changeArtist(int row)
+{
+ if (row > 0) {
+ QModelIndex index = model->relationModel(2)->index(row, 1);
+ model->setFilter("artist = '" + index.data().toString() + '\'') ;
+ showArtistProfile(index);
+ } else if (row == 0) {
+ model->setFilter(QString());
+ showImageLabel();
+ } else {
+ return;
+ }
+}
+
+void MainWindow::showArtistProfile(QModelIndex index)
+{
+ QSqlRecord record = model->relationModel(2)->record(index.row());
+
+ QString name = record.value("artist").toString();
+ QString count = record.value("albumcount").toString();
+ profileLabel->setText(tr("Artist : %1 \n" \
+ "Number of Albums: %2").arg(name).arg(count));
+
+ profileLabel->show();
+ iconLabel->show();
+
+ titleLabel->hide();
+ trackList->hide();
+ imageLabel->hide();
+}
+
+void MainWindow::showAlbumDetails(QModelIndex index)
+{
+ QSqlRecord record = model->record(index.row());
+
+ QString artist = record.value("artist").toString();
+ QString title = record.value("title").toString();
+ QString year = record.value("year").toString();
+ QString albumId = record.value("albumid").toString();
+
+ showArtistProfile(indexOfArtist(artist));
+ titleLabel->setText(tr("Title: %1 (%2)").arg(title).arg(year));
+ titleLabel->show();
+
+ QDomNodeList albums = albumData.elementsByTagName("album");
+ for (int i = 0; i < albums.count(); i++) {
+ QDomNode album = albums.item(i);
+ if (album.toElement().attribute("id") == albumId) {
+ getTrackList(album.toElement());
+ break;
+ }
+ }
+ if (!trackList->count() == 0)
+ trackList->show();
+}
+
+void MainWindow::getTrackList(QDomNode album)
+{
+ trackList->clear();
+
+ QDomNodeList tracks = album.childNodes();
+ QDomNode track;
+ QString trackNumber;
+
+ for (int j = 0; j < tracks.count(); j++) {
+
+ track = tracks.item(j);
+ trackNumber = track.toElement().attribute("number");
+
+ QListWidgetItem *item = new QListWidgetItem(trackList);
+ item->setText(trackNumber + ": " + track.toElement().text());
+ }
+}
+
+void MainWindow::addAlbum()
+{
+ Dialog *dialog = new Dialog(model, albumData, file, this);
+ int accepted = dialog->exec();
+
+ if (accepted == 1) {
+ int lastRow = model->rowCount() - 1;
+ albumView->selectRow(lastRow);
+ albumView->scrollToBottom();
+ showAlbumDetails(model->index(lastRow, 0));
+ }
+}
+
+void MainWindow::deleteAlbum()
+{
+ QModelIndexList selection = albumView->selectionModel()->selectedRows(0);
+
+ if (!selection.empty()) {
+ QModelIndex idIndex = selection.at(0);
+ int id = idIndex.data().toInt();
+ QString title = idIndex.sibling(idIndex.row(), 1).data().toString();
+ QString artist = idIndex.sibling(idIndex.row(), 2).data().toString();
+
+ QMessageBox::StandardButton button;
+ button = QMessageBox::question(this, tr("Delete Album"),
+ tr("Are you sure you want to "
+ "delete '%1' by '%2'?")
+ .arg(title, artist),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+ removeAlbumFromFile(id);
+ removeAlbumFromDatabase(idIndex);
+ decreaseAlbumCount(indexOfArtist(artist));
+
+ showImageLabel();
+ }
+ } else {
+ QMessageBox::information(this, tr("Delete Album"),
+ tr("Select the album you want to delete."));
+ }
+}
+
+void MainWindow::removeAlbumFromFile(int id)
+{
+
+ QDomNodeList albums = albumData.elementsByTagName("album");
+
+ for (int i = 0; i < albums.count(); i++) {
+ QDomNode node = albums.item(i);
+ if (node.toElement().attribute("id").toInt() == id) {
+ albumData.elementsByTagName("archive").item(0).removeChild(node);
+ break;
+ }
+ }
+/*
+ The following code is commented out since the example uses an in
+ memory database, i.e., altering the XML file will bring the data
+ out of sync.
+
+ if (!file->open(QIODevice::WriteOnly)) {
+ return;
+ } else {
+ QTextStream stream(file);
+ albumData.elementsByTagName("archive").item(0).save(stream, 4);
+ file->close();
+ }
+*/
+}
+
+void MainWindow::removeAlbumFromDatabase(QModelIndex index)
+{
+ model->removeRow(index.row());
+}
+
+void MainWindow::decreaseAlbumCount(QModelIndex artistIndex)
+{
+ int row = artistIndex.row();
+ QModelIndex albumCountIndex = artistIndex.sibling(row, 2);
+ int albumCount = albumCountIndex.data().toInt();
+
+ QSqlTableModel *artists = model->relationModel(2);
+
+ if (albumCount == 1) {
+ artists->removeRow(row);
+ showImageLabel();
+ } else {
+ artists->setData(albumCountIndex, QVariant(albumCount - 1));
+ }
+}
+
+void MainWindow::readAlbumData()
+{
+ if (!file->open(QIODevice::ReadOnly))
+ return;
+
+ if (!albumData.setContent(file)) {
+ file->close();
+ return;
+ }
+ file->close();
+}
+
+QGroupBox* MainWindow::createArtistGroupBox()
+{
+ artistView = new QComboBox;
+ artistView->setModel(model->relationModel(2));
+ artistView->setModelColumn(1);
+
+ connect(artistView, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(changeArtist(int)));
+
+ QGroupBox *box = new QGroupBox(tr("Artist"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(artistView, 0, 0);
+ box->setLayout(layout);
+
+ return box;
+}
+
+QGroupBox* MainWindow::createAlbumGroupBox()
+{
+ QGroupBox *box = new QGroupBox(tr("Album"));
+
+ albumView = new QTableView;
+ albumView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ albumView->setSortingEnabled(true);
+ albumView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ albumView->setSelectionMode(QAbstractItemView::SingleSelection);
+ albumView->setShowGrid(false);
+ albumView->verticalHeader()->hide();
+ albumView->setAlternatingRowColors(true);
+ albumView->setModel(model);
+ adjustHeader();
+
+ QLocale locale = albumView->locale();
+ locale.setNumberOptions(QLocale::OmitGroupSeparator);
+ albumView->setLocale(locale);
+
+ connect(albumView, SIGNAL(clicked(QModelIndex)),
+ this, SLOT(showAlbumDetails(QModelIndex)));
+ connect(albumView, SIGNAL(activated(QModelIndex)),
+ this, SLOT(showAlbumDetails(QModelIndex)));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(albumView, 0, 0);
+ box->setLayout(layout);
+
+ return box;
+}
+
+QGroupBox* MainWindow::createDetailsGroupBox()
+{
+ QGroupBox *box = new QGroupBox(tr("Details"));
+
+ profileLabel = new QLabel;
+ profileLabel->setWordWrap(true);
+ profileLabel->setAlignment(Qt::AlignBottom);
+
+ titleLabel = new QLabel;
+ titleLabel->setWordWrap(true);
+ titleLabel->setAlignment(Qt::AlignBottom);
+
+ iconLabel = new QLabel();
+ iconLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight);
+ iconLabel->setPixmap(QPixmap(":/images/icon.png"));
+
+ imageLabel = new QLabel;
+ imageLabel->setWordWrap(true);
+ imageLabel->setAlignment(Qt::AlignCenter);
+ imageLabel->setPixmap(QPixmap(":/images/image.png"));
+
+ trackList = new QListWidget;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(imageLabel, 0, 0, 3, 2);
+ layout->addWidget(profileLabel, 0, 0);
+ layout->addWidget(iconLabel, 0, 1);
+ layout->addWidget(titleLabel, 1, 0, 1, 2);
+ layout->addWidget(trackList, 2, 0, 1, 2);
+ layout->setRowStretch(2, 1);
+ box->setLayout(layout);
+
+ return box;
+}
+
+void MainWindow::createMenuBar()
+{
+ QAction *addAction = new QAction(tr("&Add album..."), this);
+ QAction *deleteAction = new QAction(tr("&Delete album..."), this);
+ QAction *quitAction = new QAction(tr("&Quit"), this);
+ QAction *aboutAction = new QAction(tr("&About"), this);
+ QAction *aboutQtAction = new QAction(tr("About &Qt"), this);
+
+ addAction->setShortcut(tr("Ctrl+A"));
+ deleteAction->setShortcut(tr("Ctrl+D"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(addAction);
+ fileMenu->addAction(deleteAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(quitAction);
+
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAction);
+ helpMenu->addAction(aboutQtAction);
+
+ connect(addAction, SIGNAL(triggered(bool)), this, SLOT(addAlbum()));
+ connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteAlbum()));
+ connect(quitAction, SIGNAL(triggered(bool)), this, SLOT(close()));
+ connect(aboutAction, SIGNAL(triggered(bool)), this, SLOT(about()));
+ connect(aboutQtAction, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::showImageLabel()
+{
+ profileLabel->hide();
+ titleLabel->hide();
+ iconLabel->hide();
+ trackList->hide();
+
+ imageLabel->show();
+}
+
+QModelIndex MainWindow::indexOfArtist(const QString &artist)
+{
+ QSqlTableModel *artistModel = model->relationModel(2);
+
+ for (int i = 0; i < artistModel->rowCount(); i++) {
+ QSqlRecord record = artistModel->record(i);
+ if (record.value("artist") == artist)
+ return artistModel->index(i, 1);
+ }
+ return QModelIndex();
+}
+
+void MainWindow::updateHeader(QModelIndex, int, int)
+{
+ adjustHeader();
+}
+
+void MainWindow::adjustHeader()
+{
+ albumView->hideColumn(0);
+ albumView->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
+ albumView->resizeColumnToContents(2);
+ albumView->resizeColumnToContents(3);
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Music Archive"),
+ tr("<p>The <b>Music Archive</b> example shows how to present "
+ "data from different data sources in the same application. "
+ "The album titles, and the corresponding artists and release dates, "
+ "are kept in a database, while each album's tracks are stored "
+ "in an XML file. </p><p>The example also shows how to add as "
+ "well as remove data from both the database and the "
+ "associated XML file using the API provided by the QtSql and "
+ "QtXml modules, respectively.</p>"));
+}
diff --git a/examples/sql/masterdetail/mainwindow.h b/examples/sql/masterdetail/mainwindow.h
new file mode 100644
index 0000000000..e087b68ee3
--- /dev/null
+++ b/examples/sql/masterdetail/mainwindow.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QDomDocument>
+#include <QMainWindow>
+#include <QModelIndex>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QFile;
+class QGroupBox;
+class QLabel;
+class QListWidget;
+class QSqlRelationalTableModel;
+class QTableView;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(const QString &artistTable, const QString &albumTable,
+ QFile *albumDetails, QWidget *parent = 0);
+
+private slots:
+ void about();
+ void addAlbum();
+ void changeArtist(int row);
+ void deleteAlbum();
+ void showAlbumDetails(QModelIndex index);
+ void showArtistProfile(QModelIndex index);
+ void updateHeader(QModelIndex, int, int);
+
+private:
+ void adjustHeader();
+ QGroupBox *createAlbumGroupBox();
+ QGroupBox *createArtistGroupBox();
+ QGroupBox *createDetailsGroupBox();
+ void createMenuBar();
+ void decreaseAlbumCount(QModelIndex artistIndex);
+ void getTrackList(QDomNode album);
+ QModelIndex indexOfArtist(const QString &artist);
+ void readAlbumData();
+ void removeAlbumFromDatabase(QModelIndex album);
+ void removeAlbumFromFile(int id);
+ void showImageLabel();
+
+ QTableView *albumView;
+ QComboBox *artistView;
+ QListWidget *trackList;
+
+ QLabel *iconLabel;
+ QLabel *imageLabel;
+ QLabel *profileLabel;
+ QLabel *titleLabel;
+
+ QDomDocument albumData;
+ QFile *file;
+ QSqlRelationalTableModel *model;
+};
+
+#endif
diff --git a/examples/sql/masterdetail/masterdetail.pro b/examples/sql/masterdetail/masterdetail.pro
new file mode 100644
index 0000000000..39d93ec017
--- /dev/null
+++ b/examples/sql/masterdetail/masterdetail.pro
@@ -0,0 +1,21 @@
+HEADERS = database.h \
+ dialog.h \
+ mainwindow.h
+RESOURCES = masterdetail.qrc
+SOURCES = dialog.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+QT += sql
+QT += xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/masterdetail
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS masterdetail.pro *.xml images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/masterdetail
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000D7CF
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/sql/masterdetail/masterdetail.qrc b/examples/sql/masterdetail/masterdetail.qrc
new file mode 100644
index 0000000000..717c2eb945
--- /dev/null
+++ b/examples/sql/masterdetail/masterdetail.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/icon.png</file>
+ <file>images/image.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/sql/querymodel/customsqlmodel.cpp b/examples/sql/querymodel/customsqlmodel.cpp
new file mode 100644
index 0000000000..5b09dd634b
--- /dev/null
+++ b/examples/sql/querymodel/customsqlmodel.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "customsqlmodel.h"
+
+CustomSqlModel::CustomSqlModel(QObject *parent)
+ : QSqlQueryModel(parent)
+{
+}
+
+//! [0]
+QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
+{
+ QVariant value = QSqlQueryModel::data(index, role);
+ if (value.isValid() && role == Qt::DisplayRole) {
+ if (index.column() == 0)
+ return value.toString().prepend("#");
+ else if (index.column() == 2)
+ return value.toString().toUpper();
+ }
+ if (role == Qt::TextColorRole && index.column() == 1)
+ return QVariant::fromValue(QColor(Qt::blue));
+ return value;
+}
+//! [0]
diff --git a/examples/sql/querymodel/customsqlmodel.h b/examples/sql/querymodel/customsqlmodel.h
new file mode 100644
index 0000000000..0ea1bf1e04
--- /dev/null
+++ b/examples/sql/querymodel/customsqlmodel.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CUSTOMSQLMODEL_H
+#define CUSTOMSQLMODEL_H
+
+#include <QSqlQueryModel>
+
+//! [0]
+class CustomSqlModel : public QSqlQueryModel
+{
+ Q_OBJECT
+
+public:
+ CustomSqlModel(QObject *parent = 0);
+
+ QVariant data(const QModelIndex &item, int role) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/sql/querymodel/editablesqlmodel.cpp b/examples/sql/querymodel/editablesqlmodel.cpp
new file mode 100644
index 0000000000..b47995ada3
--- /dev/null
+++ b/examples/sql/querymodel/editablesqlmodel.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtSql>
+
+#include "editablesqlmodel.h"
+
+EditableSqlModel::EditableSqlModel(QObject *parent)
+ : QSqlQueryModel(parent)
+{
+}
+
+//! [0]
+Qt::ItemFlags EditableSqlModel::flags(
+ const QModelIndex &index) const
+{
+ Qt::ItemFlags flags = QSqlQueryModel::flags(index);
+ if (index.column() == 1 || index.column() == 2)
+ flags |= Qt::ItemIsEditable;
+ return flags;
+}
+//! [0]
+
+//! [1]
+bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, int /* role */)
+{
+ if (index.column() < 1 || index.column() > 2)
+ return false;
+
+ QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0);
+ int id = data(primaryKeyIndex).toInt();
+
+ clear();
+
+ bool ok;
+ if (index.column() == 1) {
+ ok = setFirstName(id, value.toString());
+ } else {
+ ok = setLastName(id, value.toString());
+ }
+ refresh();
+ return ok;
+}
+//! [1]
+
+void EditableSqlModel::refresh()
+{
+ setQuery("select * from person");
+ setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
+ setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
+ setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
+}
+
+//! [2]
+bool EditableSqlModel::setFirstName(int personId, const QString &firstName)
+{
+ QSqlQuery query;
+ query.prepare("update person set firstname = ? where id = ?");
+ query.addBindValue(firstName);
+ query.addBindValue(personId);
+ return query.exec();
+}
+//! [2]
+
+bool EditableSqlModel::setLastName(int personId, const QString &lastName)
+{
+ QSqlQuery query;
+ query.prepare("update person set lastname = ? where id = ?");
+ query.addBindValue(lastName);
+ query.addBindValue(personId);
+ return query.exec();
+}
diff --git a/examples/sql/querymodel/editablesqlmodel.h b/examples/sql/querymodel/editablesqlmodel.h
new file mode 100644
index 0000000000..b63409d958
--- /dev/null
+++ b/examples/sql/querymodel/editablesqlmodel.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EDITABLESQLMODEL_H
+#define EDITABLESQLMODEL_H
+
+#include <QSqlQueryModel>
+
+class EditableSqlModel : public QSqlQueryModel
+{
+ Q_OBJECT
+
+public:
+ EditableSqlModel(QObject *parent = 0);
+
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+private:
+ bool setFirstName(int personId, const QString &firstName);
+ bool setLastName(int personId, const QString &lastName);
+ void refresh();
+};
+
+#endif
diff --git a/examples/sql/querymodel/main.cpp b/examples/sql/querymodel/main.cpp
new file mode 100644
index 0000000000..b6507e92c4
--- /dev/null
+++ b/examples/sql/querymodel/main.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "../connection.h"
+#include "customsqlmodel.h"
+#include "editablesqlmodel.h"
+
+void initializeModel(QSqlQueryModel *model)
+{
+ model->setQuery("select * from person");
+ model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
+ model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
+ model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
+}
+
+void createView(const QString &title, QSqlQueryModel *model)
+{
+ static int offset = 0;
+
+ QTableView *view = new QTableView;
+ view->setModel(model);
+ view->setWindowTitle(title);
+ view->move(100 + offset, 100 + offset);
+ offset += 20;
+ view->show();
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ if (!createConnection())
+ return 1;
+
+ QSqlQueryModel plainModel;
+ EditableSqlModel editableModel;
+ CustomSqlModel customModel;
+
+ initializeModel(&plainModel);
+ initializeModel(&editableModel);
+ initializeModel(&customModel);
+
+ createView(QObject::tr("Plain Query Model"), &plainModel);
+ createView(QObject::tr("Editable Query Model"), &editableModel);
+ createView(QObject::tr("Custom Query Model"), &customModel);
+
+ return app.exec();
+}
diff --git a/examples/sql/querymodel/querymodel.pro b/examples/sql/querymodel/querymodel.pro
new file mode 100644
index 0000000000..cd8b202b44
--- /dev/null
+++ b/examples/sql/querymodel/querymodel.pro
@@ -0,0 +1,15 @@
+HEADERS = ../connection.h \
+ customsqlmodel.h \
+ editablesqlmodel.h
+SOURCES = customsqlmodel.cpp \
+ editablesqlmodel.cpp \
+ main.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/querymodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS querymodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/querymodel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/sql/relationaltablemodel/relationaltablemodel.cpp b/examples/sql/relationaltablemodel/relationaltablemodel.cpp
new file mode 100644
index 0000000000..ecb985e6b5
--- /dev/null
+++ b/examples/sql/relationaltablemodel/relationaltablemodel.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSql>
+
+#include "../connection.h"
+
+void initializeModel(QSqlRelationalTableModel *model)
+{
+//! [0]
+ model->setTable("employee");
+//! [0]
+
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+//! [1]
+ model->setRelation(2, QSqlRelation("city", "id", "name"));
+//! [1] //! [2]
+ model->setRelation(3, QSqlRelation("country", "id", "name"));
+//! [2]
+
+//! [3]
+ model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
+ model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
+ model->setHeaderData(2, Qt::Horizontal, QObject::tr("City"));
+ model->setHeaderData(3, Qt::Horizontal, QObject::tr("Country"));
+//! [3]
+
+ model->select();
+}
+
+QTableView *createView(const QString &title, QSqlTableModel *model)
+{
+//! [4]
+ QTableView *view = new QTableView;
+ view->setModel(model);
+ view->setItemDelegate(new QSqlRelationalDelegate(view));
+//! [4]
+ view->setWindowTitle(title);
+ return view;
+}
+
+void createRelationalTables()
+{
+ QSqlQuery query;
+ query.exec("create table employee(id int primary key, name varchar(20), city int, country int)");
+ query.exec("insert into employee values(1, 'Espen', 5000, 47)");
+ query.exec("insert into employee values(2, 'Harald', 80000, 49)");
+ query.exec("insert into employee values(3, 'Sam', 100, 1)");
+
+ query.exec("create table city(id int, name varchar(20))");
+ query.exec("insert into city values(100, 'San Jose')");
+ query.exec("insert into city values(5000, 'Oslo')");
+ query.exec("insert into city values(80000, 'Munich')");
+
+ query.exec("create table country(id int, name varchar(20))");
+ query.exec("insert into country values(1, 'USA')");
+ query.exec("insert into country values(47, 'Norway')");
+ query.exec("insert into country values(49, 'Germany')");
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ if (!createConnection())
+ return 1;
+ createRelationalTables();
+
+ QSqlRelationalTableModel model;
+
+ initializeModel(&model);
+
+ QTableView *view = createView(QObject::tr("Relational Table Model"), &model);
+ view->show();
+
+ return app.exec();
+}
diff --git a/examples/sql/relationaltablemodel/relationaltablemodel.pro b/examples/sql/relationaltablemodel/relationaltablemodel.pro
new file mode 100644
index 0000000000..3cf3e312f2
--- /dev/null
+++ b/examples/sql/relationaltablemodel/relationaltablemodel.pro
@@ -0,0 +1,11 @@
+HEADERS = ../connection.h
+SOURCES = relationaltablemodel.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/relationaltablemodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS relationaltablemodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/relationaltablemodel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/sql/sql.pro b/examples/sql/sql.pro
new file mode 100644
index 0000000000..7de4a5c3a0
--- /dev/null
+++ b/examples/sql/sql.pro
@@ -0,0 +1,20 @@
+TEMPLATE = subdirs
+
+SUBDIRS = drilldown
+!symbian: SUBDIRS += cachedtable \
+ relationaltablemodel \
+ sqlwidgetmapper
+
+!wince*: SUBDIRS += masterdetail
+
+!wince*:!symbian: SUBDIRS += \
+ querymodel \
+ tablemodel
+
+
+# install
+sources.files = connection.h sql.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql
+INSTALLS += sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/sql/sqlwidgetmapper/main.cpp b/examples/sql/sqlwidgetmapper/main.cpp
new file mode 100644
index 0000000000..41e756d8ad
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/sql/sqlwidgetmapper/sqlwidgetmapper.pro b/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro
new file mode 100644
index 0000000000..600531881e
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/sqlwidgetmapper.pro
@@ -0,0 +1,13 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/sqlwidgetmapper
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/sqlwidgetmapper
+INSTALLS += target sources
+
+wince*: DEPLOYMENT_PLUGIN += qsqlite
+
diff --git a/examples/sql/sqlwidgetmapper/window.cpp b/examples/sql/sqlwidgetmapper/window.cpp
new file mode 100644
index 0000000000..23954c95c7
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/window.cpp
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSql>
+
+#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);
+//! [Set up widgets]
+
+//! [Set up the mapper]
+ QSqlTableModel *relModel = model->relationModel(typeIndex);
+ typeComboBox->setModel(relModel);
+ typeComboBox->setModelColumn(relModel->fieldIndex("description"));
+
+ mapper = new QDataWidgetMapper(this);
+ mapper->setModel(model);
+ mapper->setItemDelegate(new QSqlRelationalDelegate(this));
+ mapper->addMapping(nameEdit, model->fieldIndex("name"));
+ mapper->addMapping(addressEdit, model->fieldIndex("address"));
+ mapper->addMapping(typeComboBox, typeIndex);
+//! [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("SQL Widget Mapper"));
+ mapper->toFirst();
+}
+//! [Set up connections and layouts]
+
+//! [Set up the main table]
+void Window::setupModel()
+{
+ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
+ db.setDatabaseName(":memory:");
+ if (!db.open()) {
+ QMessageBox::critical(0, tr("Cannot open database"),
+ tr("Unable to establish a database connection.\n"
+ "This example needs SQLite support. Please read "
+ "the Qt SQL driver documentation for information how "
+ "to build it."), QMessageBox::Cancel);
+ return;
+ }
+
+ QSqlQuery query;
+ query.exec("create table person (id int primary key, "
+ "name varchar(20), address varchar(200), typeid int)");
+ query.exec("insert into person values(1, 'Alice', "
+ "'<qt>123 Main Street<br/>Market Town</qt>', 101)");
+ query.exec("insert into person values(2, 'Bob', "
+ "'<qt>PO Box 32<br/>Mail Handling Service"
+ "<br/>Service City</qt>', 102)");
+ query.exec("insert into person values(3, 'Carol', "
+ "'<qt>The Lighthouse<br/>Remote Island</qt>', 103)");
+ query.exec("insert into person values(4, 'Donald', "
+ "'<qt>47338 Park Avenue<br/>Big City</qt>', 101)");
+ query.exec("insert into person values(5, 'Emma', "
+ "'<qt>Research Station<br/>Base Camp<br/>"
+ "Big Mountain</qt>', 103)");
+//! [Set up the main table]
+
+//! [Set up the address type table]
+ query.exec("create table addresstype (id int, description varchar(20))");
+ query.exec("insert into addresstype values(101, 'Home')");
+ query.exec("insert into addresstype values(102, 'Work')");
+ query.exec("insert into addresstype values(103, 'Other')");
+
+ model = new QSqlRelationalTableModel(this);
+ model->setTable("person");
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+
+ typeIndex = model->fieldIndex("typeid");
+
+ model->setRelation(typeIndex,
+ QSqlRelation("addresstype", "id", "description"));
+ model->select();
+}
+//! [Set up the address type table]
+
+//! [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/sql/sqlwidgetmapper/window.h b/examples/sql/sqlwidgetmapper/window.h
new file mode 100644
index 0000000000..ee8b7d6672
--- /dev/null
+++ b/examples/sql/sqlwidgetmapper/window.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDataWidgetMapper;
+class QItemSelectionModel;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QSqlRelationalTableModel;
+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;
+
+ QSqlRelationalTableModel *model;
+ QItemSelectionModel *selectionModel;
+ QDataWidgetMapper *mapper;
+ int typeIndex;
+};
+//! [Window definition]
+
+#endif
diff --git a/examples/sql/tablemodel/tablemodel.cpp b/examples/sql/tablemodel/tablemodel.cpp
new file mode 100644
index 0000000000..41a42bc31e
--- /dev/null
+++ b/examples/sql/tablemodel/tablemodel.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtSql>
+
+#include "../connection.h"
+
+void initializeModel(QSqlTableModel *model)
+{
+ model->setTable("person");
+ model->setEditStrategy(QSqlTableModel::OnManualSubmit);
+ model->select();
+
+ model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
+ model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
+ model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
+}
+
+QTableView *createView(const QString &title, QSqlTableModel *model)
+{
+ QTableView *view = new QTableView;
+ view->setModel(model);
+ view->setWindowTitle(title);
+ return view;
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ if (!createConnection())
+ return 1;
+
+ QSqlTableModel model;
+
+ initializeModel(&model);
+
+ QTableView *view1 = createView(QObject::tr("Table Model (View 1)"), &model);
+ QTableView *view2 = createView(QObject::tr("Table Model (View 2)"), &model);
+
+ view1->show();
+ view2->move(view1->x() + view1->width() + 20, view1->y());
+ view2->show();
+
+ return app.exec();
+}
diff --git a/examples/sql/tablemodel/tablemodel.pro b/examples/sql/tablemodel/tablemodel.pro
new file mode 100644
index 0000000000..55956c05e7
--- /dev/null
+++ b/examples/sql/tablemodel/tablemodel.pro
@@ -0,0 +1,11 @@
+HEADERS = ../connection.h
+SOURCES = tablemodel.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/tablemodel
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS tablemodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/tablemodel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/statemachine/README b/examples/statemachine/README
new file mode 100644
index 0000000000..2879e67d65
--- /dev/null
+++ b/examples/statemachine/README
@@ -0,0 +1,36 @@
+Qt is provided with a powerful hierchical finite state machine through
+the Qt State Machine classes.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/statemachine/eventtransitions/eventtransitions.pro b/examples/statemachine/eventtransitions/eventtransitions.pro
new file mode 100644
index 0000000000..646c90a07d
--- /dev/null
+++ b/examples/statemachine/eventtransitions/eventtransitions.pro
@@ -0,0 +1,7 @@
+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
diff --git a/examples/statemachine/eventtransitions/main.cpp b/examples/statemachine/eventtransitions/main.cpp
new file mode 100644
index 0000000000..5391057992
--- /dev/null
+++ b/examples/statemachine/eventtransitions/main.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+//! [0]
+class Window : public QWidget
+{
+public:
+ Window(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QPushButton *button = new QPushButton(this);
+ button->setGeometry(QRect(100, 100, 100, 100));
+//! [0]
+
+//! [1]
+ QStateMachine *machine = new QStateMachine(this);
+
+ QState *s1 = new QState();
+ s1->assignProperty(button, "text", "Outside");
+
+ QState *s2 = new QState();
+ s2->assignProperty(button, "text", "Inside");
+//! [1]
+
+//! [2]
+ QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
+ enterTransition->setTargetState(s2);
+ s1->addTransition(enterTransition);
+//! [2]
+
+//! [3]
+ QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
+ leaveTransition->setTargetState(s1);
+ s2->addTransition(leaveTransition);
+//! [3]
+
+//! [4]
+ QState *s3 = new QState();
+ s3->assignProperty(button, "text", "Pressing...");
+
+ QEventTransition *pressTransition = new QEventTransition(button, QEvent::MouseButtonPress);
+ pressTransition->setTargetState(s3);
+ s2->addTransition(pressTransition);
+
+ QEventTransition *releaseTransition = new QEventTransition(button, QEvent::MouseButtonRelease);
+ releaseTransition->setTargetState(s2);
+ s3->addTransition(releaseTransition);
+//! [4]
+
+//! [5]
+ machine->addState(s1);
+ machine->addState(s2);
+ machine->addState(s3);
+
+ machine->setInitialState(s1);
+ machine->start();
+ }
+};
+//! [5]
+
+//! [6]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Window window;
+ window.resize(300, 300);
+ window.show();
+
+ return app.exec();
+}
+//! [6]
diff --git a/examples/statemachine/factorial/factorial.pro b/examples/statemachine/factorial/factorial.pro
new file mode 100644
index 0000000000..4291d43306
--- /dev/null
+++ b/examples/statemachine/factorial/factorial.pro
@@ -0,0 +1,11 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/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/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp
new file mode 100644
index 0000000000..15e1306e24
--- /dev/null
+++ b/examples/statemachine/factorial/main.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp
new file mode 100644
index 0000000000..330824d3e8
--- /dev/null
+++ b/examples/statemachine/pingpong/main.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/statemachine/pingpong/pingpong.pro b/examples/statemachine/pingpong/pingpong.pro
new file mode 100644
index 0000000000..9d2b17fc9e
--- /dev/null
+++ b/examples/statemachine/pingpong/pingpong.pro
@@ -0,0 +1,11 @@
+QT = core
+win32: CONFIG += console
+mac:CONFIG -= app_bundle
+
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/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/statemachine/rogue/main.cpp b/examples/statemachine/rogue/main.cpp
new file mode 100644
index 0000000000..71c2c69470
--- /dev/null
+++ b/examples/statemachine/rogue/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+#include "window.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Window window;
+ window.show();
+
+ return app.exec();
+}
+
diff --git a/examples/statemachine/rogue/movementtransition.h b/examples/statemachine/rogue/movementtransition.h
new file mode 100644
index 0000000000..1153b7508d
--- /dev/null
+++ b/examples/statemachine/rogue/movementtransition.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+#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;
+ }
+ 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_4:
+ window->movePlayer(Window::Left);
+ break;
+ case Qt::Key_8:
+ window->movePlayer(Window::Up);
+ break;
+ case Qt::Key_6:
+ window->movePlayer(Window::Right);
+ break;
+ case Qt::Key_2:
+ window->movePlayer(Window::Down);
+ break;
+ default:
+ ;
+ }
+ }
+//![2]
+
+private:
+ Window *window;
+};
+
+#endif
+
diff --git a/examples/statemachine/rogue/rogue.pro b/examples/statemachine/rogue/rogue.pro
new file mode 100644
index 0000000000..6ab613bea9
--- /dev/null
+++ b/examples/statemachine/rogue/rogue.pro
@@ -0,0 +1,11 @@
+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
+
diff --git a/examples/statemachine/rogue/window.cpp b/examples/statemachine/rogue/window.cpp
new file mode 100644
index 0000000000..39f5aa65d9
--- /dev/null
+++ b/examples/statemachine/rogue/window.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+#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", 12);
+ else {
+ foreach (QString family, database.families()) {
+ if (database.isFixedPitch(family)) {
+ font = QFont(family, 12);
+ break;
+ }
+ }
+ }
+ 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.drawText(QPoint(xPos, yPos), map[x][y]);
+ xPos += fontWidth;
+ }
+ }
+ 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/statemachine/rogue/window.h b/examples/statemachine/rogue/window.h
new file mode 100644
index 0000000000..025ec79600
--- /dev/null
+++ b/examples/statemachine/rogue/window.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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/statemachine/statemachine.pro b/examples/statemachine/statemachine.pro
new file mode 100644
index 0000000000..e5b8b75705
--- /dev/null
+++ b/examples/statemachine/statemachine.pro
@@ -0,0 +1,18 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ factorial \
+ pingpong
+
+!contains(QT_CONFIG, no-gui) {
+ 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/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
new file mode 100644
index 0000000000..23cd34833a
--- /dev/null
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+//! [0]
+class LightWidget : public QWidget
+{
+ Q_OBJECT
+ Q_PROPERTY(bool on READ isOn WRITE setOn)
+public:
+ LightWidget(const QColor &color, QWidget *parent = 0)
+ : QWidget(parent), m_color(color), m_on(false) {}
+
+ bool isOn() const
+ { return m_on; }
+ void setOn(bool on)
+ {
+ if (on == m_on)
+ return;
+ m_on = on;
+ update();
+ }
+
+public slots:
+ void turnOff() { setOn(false); }
+ void turnOn() { setOn(true); }
+
+protected:
+ virtual void paintEvent(QPaintEvent *)
+ {
+ if (!m_on)
+ return;
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.setBrush(m_color);
+ painter.drawEllipse(0, 0, width(), height());
+ }
+
+private:
+ QColor m_color;
+ bool m_on;
+};
+//! [0]
+
+//! [1]
+class TrafficLightWidget : public QWidget
+{
+public:
+ TrafficLightWidget(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ m_red = new LightWidget(Qt::red);
+ vbox->addWidget(m_red);
+ m_yellow = new LightWidget(Qt::yellow);
+ vbox->addWidget(m_yellow);
+ m_green = new LightWidget(Qt::green);
+ vbox->addWidget(m_green);
+ QPalette pal = palette();
+ pal.setColor(QPalette::Background, Qt::black);
+ setPalette(pal);
+ setAutoFillBackground(true);
+ }
+
+ LightWidget *redLight() const
+ { return m_red; }
+ LightWidget *yellowLight() const
+ { return m_yellow; }
+ LightWidget *greenLight() const
+ { return m_green; }
+
+private:
+ LightWidget *m_red;
+ LightWidget *m_yellow;
+ LightWidget *m_green;
+};
+//! [1]
+
+//! [2]
+QState *createLightState(LightWidget *light, int duration, QState *parent = 0)
+{
+ QState *lightState = new QState(parent);
+ QTimer *timer = new QTimer(lightState);
+ timer->setInterval(duration);
+ timer->setSingleShot(true);
+ QState *timing = new QState(lightState);
+ QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
+ QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
+ QFinalState *done = new QFinalState(lightState);
+ timing->addTransition(timer, SIGNAL(timeout()), done);
+ lightState->setInitialState(timing);
+ return lightState;
+}
+//! [2]
+
+//! [3]
+class TrafficLight : public QWidget
+{
+public:
+ TrafficLight(QWidget *parent = 0)
+ : QWidget(parent)
+ {
+ QVBoxLayout *vbox = new QVBoxLayout(this);
+ TrafficLightWidget *widget = new TrafficLightWidget();
+ vbox->addWidget(widget);
+ vbox->setMargin(0);
+
+ QStateMachine *machine = new QStateMachine(this);
+ QState *redGoingYellow = createLightState(widget->redLight(), 3000);
+ redGoingYellow->setObjectName("redGoingYellow");
+ QState *yellowGoingGreen = createLightState(widget->yellowLight(), 1000);
+ yellowGoingGreen->setObjectName("yellowGoingGreen");
+ redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
+ QState *greenGoingYellow = createLightState(widget->greenLight(), 3000);
+ greenGoingYellow->setObjectName("greenGoingYellow");
+ yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
+ QState *yellowGoingRed = createLightState(widget->yellowLight(), 1000);
+ yellowGoingRed->setObjectName("yellowGoingRed");
+ greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
+ yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
+
+ machine->addState(redGoingYellow);
+ machine->addState(yellowGoingGreen);
+ machine->addState(greenGoingYellow);
+ machine->addState(yellowGoingRed);
+ machine->setInitialState(redGoingYellow);
+ machine->start();
+ }
+};
+//! [3]
+
+//! [4]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ TrafficLight widget;
+ widget.resize(110, 300);
+ widget.show();
+
+ return app.exec();
+}
+//! [4]
+
+#include "main.moc"
diff --git a/examples/statemachine/trafficlight/trafficlight.pro b/examples/statemachine/trafficlight/trafficlight.pro
new file mode 100644
index 0000000000..f6aab8d6e5
--- /dev/null
+++ b/examples/statemachine/trafficlight/trafficlight.pro
@@ -0,0 +1,7 @@
+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
diff --git a/examples/statemachine/twowaybutton/main.cpp b/examples/statemachine/twowaybutton/main.cpp
new file mode 100644
index 0000000000..6b9ce1fe55
--- /dev/null
+++ b/examples/statemachine/twowaybutton/main.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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 <QtGui>
+
+//! [0]
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QPushButton button;
+ QStateMachine machine;
+//! [0]
+
+//! [1]
+ QState *off = new QState();
+ off->assignProperty(&button, "text", "Off");
+ off->setObjectName("off");
+
+ QState *on = new QState();
+ on->setObjectName("on");
+ on->assignProperty(&button, "text", "On");
+//! [1]
+
+//! [2]
+ off->addTransition(&button, SIGNAL(clicked()), on);
+ on->addTransition(&button, SIGNAL(clicked()), off);
+//! [2]
+
+//! [3]
+ machine.addState(off);
+ machine.addState(on);
+//! [3]
+
+//! [4]
+ machine.setInitialState(off);
+ machine.start();
+//! [4]
+
+//! [5]
+ button.resize(100, 50);
+ button.show();
+ return app.exec();
+}
+//! [5]
diff --git a/examples/statemachine/twowaybutton/twowaybutton.pro b/examples/statemachine/twowaybutton/twowaybutton.pro
new file mode 100644
index 0000000000..212ba501d7
--- /dev/null
+++ b/examples/statemachine/twowaybutton/twowaybutton.pro
@@ -0,0 +1,7 @@
+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
diff --git a/examples/symbianpkgrules.pri b/examples/symbianpkgrules.pri
new file mode 100644
index 0000000000..fe9b487d55
--- /dev/null
+++ b/examples/symbianpkgrules.pri
@@ -0,0 +1,20 @@
+!symbian: error(Only include this file for Symbian platforms)
+
+RSS_RULES ="group_name=\"QtExamples\";"
+
+nokiaVendor = "Nokia, Qt"
+vendorinfo = \
+ "; Localised Vendor name" \
+ "%{$$addLanguageDependentPkgItem(nokiaVendor)}" \
+ " " \
+ "; Unique Vendor name" \
+ ":\"$$nokiaVendor\"" \
+ " "
+
+examples_deployment.pkg_prerules += vendorinfo
+DEPLOYMENT += examples_deployment
+
+isEmpty(ICON):contains(TEMPLATE, ".*app"):contains(QT, gui):contains(CONFIG, qt):!contains(CONFIG, "no_icon") {
+ ICON = $$QT_SOURCE_TREE/src/s60installs/qt.svg
+}
+
diff --git a/examples/threads/README b/examples/threads/README
new file mode 100644
index 0000000000..e4b426f9c7
--- /dev/null
+++ b/examples/threads/README
@@ -0,0 +1,40 @@
+Qt 4 makes it easier than ever to write multithreaded applications. More
+classes have been made usable from non-GUI threads, and the signals and slots
+mechanism can now be used to communicate between threads.
+
+Additionally, it is now possible to move objects between threads.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/threads/mandelbrot/main.cpp b/examples/threads/mandelbrot/main.cpp
new file mode 100644
index 0000000000..610534d4a3
--- /dev/null
+++ b/examples/threads/mandelbrot/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mandelbrotwidget.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MandelbrotWidget widget;
+ widget.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/threads/mandelbrot/mandelbrot.pro b/examples/threads/mandelbrot/mandelbrot.pro
new file mode 100644
index 0000000000..cffaefe525
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrot.pro
@@ -0,0 +1,15 @@
+HEADERS = mandelbrotwidget.h \
+ renderthread.h
+SOURCES = main.cpp \
+ mandelbrotwidget.cpp \
+ renderthread.cpp
+
+unix:!mac:!symbian:!vxworks:!integrity:LIBS += -lm
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/mandelbrot
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS mandelbrot.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/mandelbrot
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.cpp b/examples/threads/mandelbrot/mandelbrotwidget.cpp
new file mode 100644
index 0000000000..8dc1f5d811
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrotwidget.cpp
@@ -0,0 +1,239 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+
+#include "mandelbrotwidget.h"
+
+//! [0]
+const double DefaultCenterX = -0.637011f;
+const double DefaultCenterY = -0.0395159f;
+const double DefaultScale = 0.00403897f;
+
+const double ZoomInFactor = 0.8f;
+const double ZoomOutFactor = 1 / ZoomInFactor;
+const int ScrollStep = 20;
+//! [0]
+
+//! [1]
+MandelbrotWidget::MandelbrotWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ centerX = DefaultCenterX;
+ centerY = DefaultCenterY;
+ pixmapScale = DefaultScale;
+ curScale = DefaultScale;
+
+ qRegisterMetaType<QImage>("QImage");
+ connect(&thread, SIGNAL(renderedImage(QImage,double)),
+ this, SLOT(updatePixmap(QImage,double)));
+
+ setWindowTitle(tr("Mandelbrot"));
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::CrossCursor);
+#endif
+ resize(550, 400);
+}
+//! [1]
+
+//! [2]
+void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+ painter.fillRect(rect(), Qt::black);
+
+ if (pixmap.isNull()) {
+ painter.setPen(Qt::white);
+ painter.drawText(rect(), Qt::AlignCenter,
+ tr("Rendering initial image, please wait..."));
+//! [2] //! [3]
+ return;
+//! [3] //! [4]
+ }
+//! [4]
+
+//! [5]
+ if (curScale == pixmapScale) {
+//! [5] //! [6]
+ painter.drawPixmap(pixmapOffset, pixmap);
+//! [6] //! [7]
+ } else {
+//! [7] //! [8]
+ double scaleFactor = pixmapScale / curScale;
+ int newWidth = int(pixmap.width() * scaleFactor);
+ int newHeight = int(pixmap.height() * scaleFactor);
+ int newX = pixmapOffset.x() + (pixmap.width() - newWidth) / 2;
+ int newY = pixmapOffset.y() + (pixmap.height() - newHeight) / 2;
+
+ painter.save();
+ painter.translate(newX, newY);
+ painter.scale(scaleFactor, scaleFactor);
+ QRectF exposed = painter.matrix().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
+ painter.drawPixmap(exposed, pixmap, exposed);
+ painter.restore();
+ }
+//! [8] //! [9]
+
+ QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. "
+ "Press and hold left mouse button to scroll.");
+ QFontMetrics metrics = painter.fontMetrics();
+ int textWidth = metrics.width(text);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(QColor(0, 0, 0, 127));
+ painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10,
+ metrics.lineSpacing() + 5);
+ painter.setPen(Qt::white);
+ painter.drawText((width() - textWidth) / 2,
+ metrics.leading() + metrics.ascent(), text);
+}
+//! [9]
+
+//! [10]
+void MandelbrotWidget::resizeEvent(QResizeEvent * /* event */)
+{
+ thread.render(centerX, centerY, curScale, size());
+}
+//! [10]
+
+//! [11]
+void MandelbrotWidget::keyPressEvent(QKeyEvent *event)
+{
+ switch (event->key()) {
+ case Qt::Key_Plus:
+ zoom(ZoomInFactor);
+ break;
+ case Qt::Key_Minus:
+ zoom(ZoomOutFactor);
+ break;
+ case Qt::Key_Left:
+ scroll(-ScrollStep, 0);
+ break;
+ case Qt::Key_Right:
+ scroll(+ScrollStep, 0);
+ break;
+ case Qt::Key_Down:
+ scroll(0, -ScrollStep);
+ break;
+ case Qt::Key_Up:
+ scroll(0, +ScrollStep);
+ break;
+ default:
+ QWidget::keyPressEvent(event);
+ }
+}
+//! [11]
+
+//! [12]
+void MandelbrotWidget::wheelEvent(QWheelEvent *event)
+{
+ int numDegrees = event->delta() / 8;
+ double numSteps = numDegrees / 15.0f;
+ zoom(pow(ZoomInFactor, numSteps));
+}
+//! [12]
+
+//! [13]
+void MandelbrotWidget::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton)
+ lastDragPos = event->pos();
+}
+//! [13]
+
+//! [14]
+void MandelbrotWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ if (event->buttons() & Qt::LeftButton) {
+ pixmapOffset += event->pos() - lastDragPos;
+ lastDragPos = event->pos();
+ update();
+ }
+}
+//! [14]
+
+//! [15]
+void MandelbrotWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ pixmapOffset += event->pos() - lastDragPos;
+ lastDragPos = QPoint();
+
+ int deltaX = (width() - pixmap.width()) / 2 - pixmapOffset.x();
+ int deltaY = (height() - pixmap.height()) / 2 - pixmapOffset.y();
+ scroll(deltaX, deltaY);
+ }
+}
+//! [15]
+
+//! [16]
+void MandelbrotWidget::updatePixmap(const QImage &image, double scaleFactor)
+{
+ if (!lastDragPos.isNull())
+ return;
+
+ pixmap = QPixmap::fromImage(image);
+ pixmapOffset = QPoint();
+ lastDragPos = QPoint();
+ pixmapScale = scaleFactor;
+ update();
+}
+//! [16]
+
+//! [17]
+void MandelbrotWidget::zoom(double zoomFactor)
+{
+ curScale *= zoomFactor;
+ update();
+ thread.render(centerX, centerY, curScale, size());
+}
+//! [17]
+
+//! [18]
+void MandelbrotWidget::scroll(int deltaX, int deltaY)
+{
+ centerX += deltaX * curScale;
+ centerY += deltaY * curScale;
+ update();
+ thread.render(centerX, centerY, curScale, size());
+}
+//! [18]
diff --git a/examples/threads/mandelbrot/mandelbrotwidget.h b/examples/threads/mandelbrot/mandelbrotwidget.h
new file mode 100644
index 0000000000..5af3a8dffd
--- /dev/null
+++ b/examples/threads/mandelbrot/mandelbrotwidget.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MANDELBROTWIDGET_H
+#define MANDELBROTWIDGET_H
+
+#include <QPixmap>
+#include <QWidget>
+
+#include "renderthread.h"
+
+//! [0]
+class MandelbrotWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MandelbrotWidget(QWidget *parent = 0);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+ void wheelEvent(QWheelEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private slots:
+ void updatePixmap(const QImage &image, double scaleFactor);
+
+private:
+ void zoom(double zoomFactor);
+ void scroll(int deltaX, int deltaY);
+
+ RenderThread thread;
+ QPixmap pixmap;
+ QPoint pixmapOffset;
+ QPoint lastDragPos;
+ double centerX;
+ double centerY;
+ double pixmapScale;
+ double curScale;
+};
+//! [0]
+
+#endif
diff --git a/examples/threads/mandelbrot/renderthread.cpp b/examples/threads/mandelbrot/renderthread.cpp
new file mode 100644
index 0000000000..da89f99e5c
--- /dev/null
+++ b/examples/threads/mandelbrot/renderthread.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+
+#include "renderthread.h"
+
+//! [0]
+RenderThread::RenderThread(QObject *parent)
+ : QThread(parent)
+{
+ restart = false;
+ abort = false;
+
+ for (int i = 0; i < ColormapSize; ++i)
+ colormap[i] = rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize));
+}
+//! [0]
+
+//! [1]
+RenderThread::~RenderThread()
+{
+ mutex.lock();
+ abort = true;
+ condition.wakeOne();
+ mutex.unlock();
+
+ wait();
+}
+//! [1]
+
+//! [2]
+void RenderThread::render(double centerX, double centerY, double scaleFactor,
+ QSize resultSize)
+{
+ QMutexLocker locker(&mutex);
+
+ this->centerX = centerX;
+ this->centerY = centerY;
+ this->scaleFactor = scaleFactor;
+ this->resultSize = resultSize;
+
+ if (!isRunning()) {
+ start(LowPriority);
+ } else {
+ restart = true;
+ condition.wakeOne();
+ }
+}
+//! [2]
+
+//! [3]
+void RenderThread::run()
+{
+ forever {
+ mutex.lock();
+ QSize resultSize = this->resultSize;
+ double scaleFactor = this->scaleFactor;
+ double centerX = this->centerX;
+ double centerY = this->centerY;
+ mutex.unlock();
+//! [3]
+
+//! [4]
+ int halfWidth = resultSize.width() / 2;
+//! [4] //! [5]
+ int halfHeight = resultSize.height() / 2;
+ QImage image(resultSize, QImage::Format_RGB32);
+
+ const int NumPasses = 8;
+ int pass = 0;
+ while (pass < NumPasses) {
+ const int MaxIterations = (1 << (2 * pass + 6)) + 32;
+ const int Limit = 4;
+ bool allBlack = true;
+
+ for (int y = -halfHeight; y < halfHeight; ++y) {
+ if (restart)
+ break;
+ if (abort)
+ return;
+
+ uint *scanLine =
+ reinterpret_cast<uint *>(image.scanLine(y + halfHeight));
+ double ay = centerY + (y * scaleFactor);
+
+ for (int x = -halfWidth; x < halfWidth; ++x) {
+ double ax = centerX + (x * scaleFactor);
+ double a1 = ax;
+ double b1 = ay;
+ int numIterations = 0;
+
+ do {
+ ++numIterations;
+ double a2 = (a1 * a1) - (b1 * b1) + ax;
+ double b2 = (2 * a1 * b1) + ay;
+ if ((a2 * a2) + (b2 * b2) > Limit)
+ break;
+
+ ++numIterations;
+ a1 = (a2 * a2) - (b2 * b2) + ax;
+ b1 = (2 * a2 * b2) + ay;
+ if ((a1 * a1) + (b1 * b1) > Limit)
+ break;
+ } while (numIterations < MaxIterations);
+
+ if (numIterations < MaxIterations) {
+ *scanLine++ = colormap[numIterations % ColormapSize];
+ allBlack = false;
+ } else {
+ *scanLine++ = qRgb(0, 0, 0);
+ }
+ }
+ }
+
+ if (allBlack && pass == 0) {
+ pass = 4;
+ } else {
+ if (!restart)
+ emit renderedImage(image, scaleFactor);
+//! [5] //! [6]
+ ++pass;
+ }
+//! [6] //! [7]
+ }
+//! [7]
+
+//! [8]
+ mutex.lock();
+//! [8] //! [9]
+ if (!restart)
+ condition.wait(&mutex);
+ restart = false;
+ mutex.unlock();
+ }
+}
+//! [9]
+
+//! [10]
+uint RenderThread::rgbFromWaveLength(double wave)
+{
+ double r = 0.0;
+ double g = 0.0;
+ double b = 0.0;
+
+ if (wave >= 380.0 && wave <= 440.0) {
+ r = -1.0 * (wave - 440.0) / (440.0 - 380.0);
+ b = 1.0;
+ } else if (wave >= 440.0 && wave <= 490.0) {
+ g = (wave - 440.0) / (490.0 - 440.0);
+ b = 1.0;
+ } else if (wave >= 490.0 && wave <= 510.0) {
+ g = 1.0;
+ b = -1.0 * (wave - 510.0) / (510.0 - 490.0);
+ } else if (wave >= 510.0 && wave <= 580.0) {
+ r = (wave - 510.0) / (580.0 - 510.0);
+ g = 1.0;
+ } else if (wave >= 580.0 && wave <= 645.0) {
+ r = 1.0;
+ g = -1.0 * (wave - 645.0) / (645.0 - 580.0);
+ } else if (wave >= 645.0 && wave <= 780.0) {
+ r = 1.0;
+ }
+
+ double s = 1.0;
+ if (wave > 700.0)
+ s = 0.3 + 0.7 * (780.0 - wave) / (780.0 - 700.0);
+ else if (wave < 420.0)
+ s = 0.3 + 0.7 * (wave - 380.0) / (420.0 - 380.0);
+
+ r = pow(r * s, 0.8);
+ g = pow(g * s, 0.8);
+ b = pow(b * s, 0.8);
+ return qRgb(int(r * 255), int(g * 255), int(b * 255));
+}
+//! [10]
diff --git a/examples/threads/mandelbrot/renderthread.h b/examples/threads/mandelbrot/renderthread.h
new file mode 100644
index 0000000000..3370d9df4b
--- /dev/null
+++ b/examples/threads/mandelbrot/renderthread.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENDERTHREAD_H
+#define RENDERTHREAD_H
+
+#include <QMutex>
+#include <QSize>
+#include <QThread>
+#include <QWaitCondition>
+
+QT_BEGIN_NAMESPACE
+class QImage;
+QT_END_NAMESPACE
+
+//! [0]
+class RenderThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ RenderThread(QObject *parent = 0);
+ ~RenderThread();
+
+ void render(double centerX, double centerY, double scaleFactor,
+ QSize resultSize);
+
+signals:
+ void renderedImage(const QImage &image, double scaleFactor);
+
+protected:
+ void run();
+
+private:
+ uint rgbFromWaveLength(double wave);
+
+ QMutex mutex;
+ QWaitCondition condition;
+ double centerX;
+ double centerY;
+ double scaleFactor;
+ QSize resultSize;
+ bool restart;
+ bool abort;
+
+ enum { ColormapSize = 512 };
+ uint colormap[ColormapSize];
+};
+//! [0]
+
+#endif
diff --git a/examples/threads/queuedcustomtype/block.cpp b/examples/threads/queuedcustomtype/block.cpp
new file mode 100644
index 0000000000..a4252cb258
--- /dev/null
+++ b/examples/threads/queuedcustomtype/block.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QColor>
+#include <QRect>
+#include "block.h"
+
+Block::Block()
+{
+}
+
+Block::Block(const Block &other)
+{
+ m_rect = other.m_rect;
+ m_color = other.m_color;
+}
+
+Block::~Block()
+{
+}
+
+Block::Block(const QRect &rect, const QColor &color)
+{
+ m_rect = rect;
+ m_color = color;
+}
+
+QColor Block::color() const
+{
+ return m_color;
+}
+
+QRect Block::rect() const
+{
+ return m_rect;
+}
diff --git a/examples/threads/queuedcustomtype/block.h b/examples/threads/queuedcustomtype/block.h
new file mode 100644
index 0000000000..1c37f82d0e
--- /dev/null
+++ b/examples/threads/queuedcustomtype/block.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BLOCK_H
+#define BLOCK_H
+
+#include <QColor>
+#include <QDebug>
+#include <QMetaType>
+#include <QRect>
+
+//! [custom type definition and meta-type declaration]
+class Block
+{
+public:
+ Block();
+ Block(const Block &other);
+ ~Block();
+
+ Block(const QRect &rect, const QColor &color);
+
+ QColor color() const;
+ QRect rect() const;
+
+private:
+ QRect m_rect;
+ QColor m_color;
+};
+
+Q_DECLARE_METATYPE(Block);
+//! [custom type definition and meta-type declaration]
+
+#endif
diff --git a/examples/threads/queuedcustomtype/main.cpp b/examples/threads/queuedcustomtype/main.cpp
new file mode 100644
index 0000000000..d70a88a095
--- /dev/null
+++ b/examples/threads/queuedcustomtype/main.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QPainter>
+#include <QTime>
+#include "block.h"
+#include "window.h"
+
+QImage createImage(int width, int height)
+{
+ QImage image(width, height, QImage::Format_RGB16);
+ QPainter painter;
+ QPen pen;
+ pen.setStyle(Qt::NoPen);
+ QBrush brush(Qt::blue);
+
+ painter.begin(&image);
+ painter.fillRect(image.rect(), brush);
+ brush.setColor(Qt::white);
+ painter.setPen(pen);
+ painter.setBrush(brush);
+
+ static const QPointF points1[3] = {
+ QPointF(4, 4),
+ QPointF(7, 4),
+ QPointF(5.5, 1)
+ };
+
+ static const QPointF points2[3] = {
+ QPointF(1, 4),
+ QPointF(7, 4),
+ QPointF(10, 10)
+ };
+
+ static const QPointF points3[3] = {
+ QPointF(4, 4),
+ QPointF(10, 4),
+ QPointF(1, 10)
+ };
+
+ painter.setWindow(0, 0, 10, 10);
+
+ int x = 0;
+ int y = 0;
+ int starWidth = image.width()/3;
+ int starHeight = image.height()/3;
+
+ QRect rect(x, y, starWidth, starHeight);
+
+ for (int i = 0; i < 9; ++i) {
+
+ painter.setViewport(rect);
+ painter.drawPolygon(points1, 3);
+ painter.drawPolygon(points2, 3);
+ painter.drawPolygon(points3, 3);
+
+ if (i % 3 == 2) {
+ y = y + starHeight;
+ rect.moveTop(y);
+
+ x = 0;
+ rect.moveLeft(x);
+
+ } else {
+ x = x + starWidth;
+ rect.moveLeft(x);
+ }
+ }
+
+ painter.end();
+ return image;
+}
+
+//! [main function] //! [main start]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+//! [main start] //! [register meta-type for queued communications]
+ qRegisterMetaType<Block>();
+//! [register meta-type for queued communications]
+ qsrand(QTime::currentTime().elapsed());
+
+ Window window;
+ window.show();
+
+ window.loadImage(createImage(256, 256));
+//! [main finish]
+ return app.exec();
+}
+//! [main finish] //! [main function]
diff --git a/examples/threads/queuedcustomtype/queuedcustomtype.pro b/examples/threads/queuedcustomtype/queuedcustomtype.pro
new file mode 100644
index 0000000000..6f39121df7
--- /dev/null
+++ b/examples/threads/queuedcustomtype/queuedcustomtype.pro
@@ -0,0 +1,7 @@
+HEADERS = block.h \
+ renderthread.h \
+ window.h
+SOURCES = main.cpp \
+ block.cpp \
+ renderthread.cpp \
+ window.cpp
diff --git a/examples/threads/queuedcustomtype/renderthread.cpp b/examples/threads/queuedcustomtype/renderthread.cpp
new file mode 100644
index 0000000000..a44ac2315a
--- /dev/null
+++ b/examples/threads/queuedcustomtype/renderthread.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "renderthread.h"
+
+RenderThread::RenderThread(QObject *parent)
+ : QThread(parent)
+{
+ m_abort = false;
+}
+
+RenderThread::~RenderThread()
+{
+ mutex.lock();
+ m_abort = true;
+ mutex.unlock();
+
+ wait();
+}
+
+//![processing the image (start)]
+void RenderThread::processImage(const QImage &image)
+{
+ if (image.isNull())
+ return;
+
+ m_image = image;
+ m_abort = false;
+ start();
+}
+
+void RenderThread::run()
+{
+ int size = qMax(m_image.width()/20, m_image.height()/20);
+ for (int s = size; s > 0; --s) {
+ for (int c = 0; c < 400; ++c) {
+//![processing the image (start)]
+ int x1 = qMax(0, (qrand() % m_image.width()) - s/2);
+ int x2 = qMin(x1 + s/2 + 1, m_image.width());
+ int y1 = qMax(0, (qrand() % m_image.height()) - s/2);
+ int y2 = qMin(y1 + s/2 + 1, m_image.height());
+ int n = 0;
+ int red = 0;
+ int green = 0;
+ int blue = 0;
+ for (int i = y1; i < y2; ++i) {
+ for (int j = x1; j < x2; ++j) {
+ QRgb pixel = m_image.pixel(j, i);
+ red += qRed(pixel);
+ green += qGreen(pixel);
+ blue += qBlue(pixel);
+ n += 1;
+ }
+ }
+//![processing the image (finish)]
+ Block block(QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1),
+ QColor(red/n, green/n, blue/n));
+ emit sendBlock(block);
+ if (m_abort)
+ return;
+ msleep(10);
+ }
+ }
+}
+//![processing the image (finish)]
+
+void RenderThread::stopProcess()
+{
+ mutex.lock();
+ m_abort = true;
+ mutex.unlock();
+}
diff --git a/examples/threads/queuedcustomtype/renderthread.h b/examples/threads/queuedcustomtype/renderthread.h
new file mode 100644
index 0000000000..99f72c3e01
--- /dev/null
+++ b/examples/threads/queuedcustomtype/renderthread.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RENDERTHREAD_H
+#define RENDERTHREAD_H
+
+#include <QImage>
+#include <QMutex>
+#include <QThread>
+#include "block.h"
+
+//! [RenderThread class definition]
+class RenderThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ RenderThread(QObject *parent = 0);
+ ~RenderThread();
+
+ void processImage(const QImage &image);
+
+signals:
+ void sendBlock(const Block &block);
+
+public slots:
+ void stopProcess();
+
+protected:
+ void run();
+
+private:
+ bool m_abort;
+ QImage m_image;
+ QMutex mutex;
+};
+//! [RenderThread class definition]
+
+#endif
diff --git a/examples/threads/queuedcustomtype/window.cpp b/examples/threads/queuedcustomtype/window.cpp
new file mode 100644
index 0000000000..367b75818f
--- /dev/null
+++ b/examples/threads/queuedcustomtype/window.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "window.h"
+
+//! [Window constructor start]
+Window::Window()
+{
+ thread = new RenderThread();
+//! [Window constructor start] //! [set up widgets and connections]
+
+ label = new QLabel();
+ label->setAlignment(Qt::AlignCenter);
+
+ loadButton = new QPushButton(tr("&Load image..."));
+ resetButton = new QPushButton(tr("&Stop"));
+ resetButton->setEnabled(false);
+
+ connect(loadButton, SIGNAL(clicked()), this, SLOT(loadImage()));
+ connect(resetButton, SIGNAL(clicked()), thread, SLOT(stopProcess()));
+ connect(thread, SIGNAL(finished()), this, SLOT(resetUi()));
+//! [set up widgets and connections] //! [connecting signal with custom type]
+ connect(thread, SIGNAL(sendBlock(Block)), this, SLOT(addBlock(Block)));
+//! [connecting signal with custom type]
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout();
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(loadButton);
+ buttonLayout->addWidget(resetButton);
+ buttonLayout->addStretch();
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(label);
+ layout->addLayout(buttonLayout);
+
+//! [Window constructor finish]
+ setWindowTitle(tr("Queued Custom Type"));
+}
+//! [Window constructor finish]
+
+void Window::loadImage()
+{
+ QStringList formats;
+ foreach (QByteArray format, QImageReader::supportedImageFormats())
+ if (format.toLower() == format)
+ formats.append("*." + format);
+
+ QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"),
+ path, tr("Image files (%1)").arg(formats.join(" ")));
+
+ if (newPath.isEmpty())
+ return;
+
+ QImage image(newPath);
+ if (!image.isNull()) {
+ loadImage(image);
+ path = newPath;
+ }
+}
+
+void Window::loadImage(const QImage &image)
+{
+ QDesktopWidget desktop;
+ QImage useImage;
+ QRect space = desktop.availableGeometry();
+ if (image.width() > 0.75*space.width() || image.height() > 0.75*space.height())
+ useImage = image.scaled(0.75*space.width(), 0.75*space.height(),
+ Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ else
+ useImage = image;
+
+ pixmap = QPixmap(useImage.width(), useImage.height());
+ pixmap.fill(qRgb(255, 255, 255));
+ label->setPixmap(pixmap);
+ loadButton->setEnabled(false);
+ resetButton->setEnabled(true);
+ thread->processImage(useImage);
+}
+
+//! [Adding blocks to the display]
+void Window::addBlock(const Block &block)
+{
+ QColor color = block.color();
+ color.setAlpha(64);
+
+ QPainter painter;
+ painter.begin(&pixmap);
+ painter.fillRect(block.rect(), color);
+ painter.end();
+ label->setPixmap(pixmap);
+}
+//! [Adding blocks to the display]
+
+void Window::resetUi()
+{
+ loadButton->setEnabled(true);
+ resetButton->setEnabled(false);
+}
diff --git a/examples/threads/queuedcustomtype/window.h b/examples/threads/queuedcustomtype/window.h
new file mode 100644
index 0000000000..539c240cd7
--- /dev/null
+++ b/examples/threads/queuedcustomtype/window.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include "renderthread.h"
+
+class QLabel;
+class QPushButton;
+
+//! [Window class definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+ void loadImage(const QImage &image);
+
+public slots:
+ void addBlock(const Block &block);
+
+private slots:
+ void loadImage();
+ void resetUi();
+
+private:
+ QLabel *label;
+ QPixmap pixmap;
+ QPushButton *loadButton;
+ QPushButton *resetButton;
+ QString path;
+ RenderThread *thread;
+};
+//! [Window class definition]
+
+#endif
diff --git a/examples/threads/semaphores/semaphores.cpp b/examples/threads/semaphores/semaphores.cpp
new file mode 100644
index 0000000000..88630def09
--- /dev/null
+++ b/examples/threads/semaphores/semaphores.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+//! [0]
+const int DataSize = 100000;
+const int BufferSize = 8192;
+char buffer[BufferSize];
+
+QSemaphore freeBytes(BufferSize);
+QSemaphore usedBytes;
+//! [0]
+
+//! [1]
+class Producer : public QThread
+//! [1] //! [2]
+{
+public:
+ void run();
+};
+
+void Producer::run()
+{
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ for (int i = 0; i < DataSize; ++i) {
+ freeBytes.acquire();
+ buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
+ usedBytes.release();
+ }
+}
+//! [2]
+
+//! [3]
+class Consumer : public QThread
+//! [3] //! [4]
+{
+public:
+ void run();
+};
+
+void Consumer::run()
+{
+ for (int i = 0; i < DataSize; ++i) {
+ usedBytes.acquire();
+ fprintf(stderr, "%c", buffer[i % BufferSize]);
+ freeBytes.release();
+ }
+ fprintf(stderr, "\n");
+}
+//! [4]
+
+//! [5]
+int main(int argc, char *argv[])
+//! [5] //! [6]
+{
+ QCoreApplication app(argc, argv);
+ Producer producer;
+ Consumer consumer;
+ producer.start();
+ consumer.start();
+ producer.wait();
+ consumer.wait();
+ return 0;
+}
+//! [6]
diff --git a/examples/threads/semaphores/semaphores.pro b/examples/threads/semaphores/semaphores.pro
new file mode 100644
index 0000000000..027c65ca5e
--- /dev/null
+++ b/examples/threads/semaphores/semaphores.pro
@@ -0,0 +1,12 @@
+SOURCES += semaphores.cpp
+QT = core
+CONFIG -= app_bundle
+CONFIG += console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/semaphores
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS semaphores.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/semaphores
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/threads/threads.pro b/examples/threads/threads.pro
new file mode 100644
index 0000000000..e8f8c09ab9
--- /dev/null
+++ b/examples/threads/threads.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+SUBDIRS = semaphores \
+ waitconditions
+
+!contains(QT_CONFIG, no-gui):SUBDIRS += mandelbrot
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS threads.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/threads/waitconditions/waitconditions.cpp b/examples/threads/waitconditions/waitconditions.cpp
new file mode 100644
index 0000000000..5c8cb7149f
--- /dev/null
+++ b/examples/threads/waitconditions/waitconditions.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+//! [0]
+const int DataSize = 100000;
+const int BufferSize = 8192;
+char buffer[BufferSize];
+
+QWaitCondition bufferNotEmpty;
+QWaitCondition bufferNotFull;
+QMutex mutex;
+int numUsedBytes = 0;
+//! [0]
+
+//! [1]
+class Producer : public QThread
+//! [1] //! [2]
+{
+public:
+ void run();
+};
+
+void Producer::run()
+{
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ for (int i = 0; i < DataSize; ++i) {
+ mutex.lock();
+ if (numUsedBytes == BufferSize)
+ bufferNotFull.wait(&mutex);
+ mutex.unlock();
+
+ buffer[i % BufferSize] = "ACGT"[(int)qrand() % 4];
+
+ mutex.lock();
+ ++numUsedBytes;
+ bufferNotEmpty.wakeAll();
+ mutex.unlock();
+ }
+}
+//! [2]
+
+//! [3]
+class Consumer : public QThread
+//! [3] //! [4]
+{
+public:
+ void run();
+};
+
+void Consumer::run()
+{
+ for (int i = 0; i < DataSize; ++i) {
+ mutex.lock();
+ if (numUsedBytes == 0)
+ bufferNotEmpty.wait(&mutex);
+ mutex.unlock();
+
+ fprintf(stderr, "%c", buffer[i % BufferSize]);
+
+ mutex.lock();
+ --numUsedBytes;
+ bufferNotFull.wakeAll();
+ mutex.unlock();
+ }
+ fprintf(stderr, "\n");
+}
+//! [4]
+
+//! [5]
+int main(int argc, char *argv[])
+//! [5] //! [6]
+{
+ QCoreApplication app(argc, argv);
+ Producer producer;
+ Consumer consumer;
+ producer.start();
+ consumer.start();
+ producer.wait();
+ consumer.wait();
+ return 0;
+}
+//! [6]
diff --git a/examples/threads/waitconditions/waitconditions.pro b/examples/threads/waitconditions/waitconditions.pro
new file mode 100644
index 0000000000..a2359c3d84
--- /dev/null
+++ b/examples/threads/waitconditions/waitconditions.pro
@@ -0,0 +1,21 @@
+######################################################################
+# Automatically generated by qmake (1.08a) Fri Jan 7 15:25:07 2005
+######################################################################
+
+TEMPLATE = app
+CONFIG -= moc app_bundle
+QT -= gui
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += waitconditions.cpp
+CONFIG += qt warn_on create_prl link_prl console
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/waitconditions
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS waitconditions.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/threads/waitconditions
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/README b/examples/tools/README
new file mode 100644
index 0000000000..b0926f2fb6
--- /dev/null
+++ b/examples/tools/README
@@ -0,0 +1,40 @@
+Qt is equipped with a range of capable tool classes, from containers and
+iterators to classes for string handling and manipulation.
+
+Other classes provide application infrastructure support, handling plugin
+loading and managing configuration files.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/tools/codecs/codecs.pro b/examples/tools/codecs/codecs.pro
new file mode 100644
index 0000000000..097601fa0b
--- /dev/null
+++ b/examples/tools/codecs/codecs.pro
@@ -0,0 +1,13 @@
+HEADERS += mainwindow.h \
+ previewform.h
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ previewform.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/codecs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS encodedfiles codecs.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/codecs
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-1.txt b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
new file mode 100644
index 0000000000..d7fcacae66
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-1.txt
@@ -0,0 +1,6 @@
+Paulo Coelho: O Gnio e as Rosas
+Anna Hallstrm, Urban stberg: Svr svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schlo
+Walter Moers: Die 13 Leben des Kpt'n Blaubr
+Dag Solstad: Forsk p beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/iso-8859-15.txt b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
new file mode 100644
index 0000000000..be2d83c98d
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/iso-8859-15.txt
@@ -0,0 +1,8 @@
+Paulo Coelho: O Gnio e as Rosas
+Jean-Pierre Coffe: table en famille avec 15 par jour
+Anna Hallstrm, Urban stberg: Svr svenska
+Darrell Huff: How to Lie with Statistics
+Franz Kafka: Das Schlo
+Helena Leheckov: Tekki suomalaisille
+Arthur Rimbaud: uvres compltes
+Dag Solstad: Forsk p beskrive det ugjennomtrengelige
diff --git a/examples/tools/codecs/encodedfiles/utf-16.txt b/examples/tools/codecs/encodedfiles/utf-16.txt
new file mode 100644
index 0000000000..371f06f7fa
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16be.txt b/examples/tools/codecs/encodedfiles/utf-16be.txt
new file mode 100644
index 0000000000..d8ae6428bc
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16be.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-16le.txt b/examples/tools/codecs/encodedfiles/utf-16le.txt
new file mode 100644
index 0000000000..3779264c7c
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-16le.txt
Binary files differ
diff --git a/examples/tools/codecs/encodedfiles/utf-8.txt b/examples/tools/codecs/encodedfiles/utf-8.txt
new file mode 100644
index 0000000000..a5e4ae6fa7
--- /dev/null
+++ b/examples/tools/codecs/encodedfiles/utf-8.txt
@@ -0,0 +1,6 @@
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
diff --git a/examples/tools/codecs/main.cpp b/examples/tools/codecs/main.cpp
new file mode 100644
index 0000000000..923c1f8514
--- /dev/null
+++ b/examples/tools/codecs/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/tools/codecs/mainwindow.cpp b/examples/tools/codecs/mainwindow.cpp
new file mode 100644
index 0000000000..25eda1d2ba
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "previewform.h"
+
+MainWindow::MainWindow()
+{
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ setCentralWidget(textEdit);
+
+ findCodecs();
+
+ previewForm = new PreviewForm(this);
+ previewForm->setCodecList(codecs);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Codecs"));
+ resize(500, 400);
+}
+
+void MainWindow::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot read file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QByteArray data = file.readAll();
+
+ previewForm->setEncodedData(data);
+ if (previewForm->exec())
+ textEdit->setPlainText(previewForm->decodedString());
+ }
+}
+
+void MainWindow::save()
+{
+ QString fileName = QFileDialog::getSaveFileName(this);
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot write file %1:\n%2")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QAction *action = qobject_cast<QAction *>(sender());
+ QByteArray codecName = action->data().toByteArray();
+
+ QTextStream out(&file);
+ out.setCodec(codecName);
+ out << textEdit->toPlainText();
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Codecs"),
+ tr("The <b>Codecs</b> example demonstrates how to read and write "
+ "files using various encodings."));
+}
+
+void MainWindow::aboutToShowSaveAsMenu()
+{
+ QString currentText = textEdit->toPlainText();
+
+ foreach (QAction *action, saveAsActs) {
+ QByteArray codecName = action->data().toByteArray();
+ QTextCodec *codec = QTextCodec::codecForName(codecName);
+ action->setVisible(codec && codec->canEncode(currentText));
+ }
+}
+
+void MainWindow::findCodecs()
+{
+ QMap<QString, QTextCodec *> codecMap;
+ QRegExp iso8859RegExp("ISO[- ]8859-([0-9]+).*");
+
+ foreach (int mib, QTextCodec::availableMibs()) {
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QString sortKey = codec->name().toUpper();
+ int rank;
+
+ if (sortKey.startsWith("UTF-8")) {
+ rank = 1;
+ } else if (sortKey.startsWith("UTF-16")) {
+ rank = 2;
+ } else if (iso8859RegExp.exactMatch(sortKey)) {
+ if (iso8859RegExp.cap(1).size() == 1)
+ rank = 3;
+ else
+ rank = 4;
+ } else {
+ rank = 5;
+ }
+ sortKey.prepend(QChar('0' + rank));
+
+ codecMap.insert(sortKey, codec);
+ }
+ codecs = codecMap.values();
+}
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ foreach (QTextCodec *codec, codecs) {
+ QString text = tr("%1...").arg(QString(codec->name()));
+
+ QAction *action = new QAction(text, this);
+ action->setData(codec->name());
+ connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ saveAsActs.append(action);
+ }
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ saveAsMenu = new QMenu(tr("&Save As"), this);
+ foreach (QAction *action, saveAsActs)
+ saveAsMenu->addAction(action);
+ connect(saveAsMenu, SIGNAL(aboutToShow()),
+ this, SLOT(aboutToShowSaveAsMenu()));
+
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addMenu(saveAsMenu);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addSeparator();
+ menuBar()->addMenu(helpMenu);
+}
diff --git a/examples/tools/codecs/mainwindow.h b/examples/tools/codecs/mainwindow.h
new file mode 100644
index 0000000000..9a59e27310
--- /dev/null
+++ b/examples/tools/codecs/mainwindow.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+class PreviewForm;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ void save();
+ void about();
+ void aboutToShowSaveAsMenu();
+
+private:
+ void findCodecs();
+ void createActions();
+ void createMenus();
+
+ QTextEdit *textEdit;
+ PreviewForm *previewForm;
+ QList<QTextCodec *> codecs;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QMenu *saveAsMenu;
+ QAction *openAct;
+ QList<QAction *> saveAsActs;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/tools/codecs/previewform.cpp b/examples/tools/codecs/previewform.cpp
new file mode 100644
index 0000000000..523be6cb0f
--- /dev/null
+++ b/examples/tools/codecs/previewform.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "previewform.h"
+
+PreviewForm::PreviewForm(QWidget *parent)
+ : QDialog(parent)
+{
+ encodingComboBox = new QComboBox;
+
+ encodingLabel = new QLabel(tr("&Encoding:"));
+ encodingLabel->setBuddy(encodingComboBox);
+
+ textEdit = new QTextEdit;
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ textEdit->setReadOnly(true);
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(encodingComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateTextEdit()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(encodingLabel, 0, 0);
+ mainLayout->addWidget(encodingComboBox, 0, 1);
+ mainLayout->addWidget(textEdit, 1, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Choose Encoding"));
+ resize(400, 300);
+}
+
+void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
+{
+ encodingComboBox->clear();
+ foreach (QTextCodec *codec, list)
+ encodingComboBox->addItem(codec->name(), codec->mibEnum());
+}
+
+void PreviewForm::setEncodedData(const QByteArray &data)
+{
+ encodedData = data;
+ updateTextEdit();
+}
+
+void PreviewForm::updateTextEdit()
+{
+ int mib = encodingComboBox->itemData(
+ encodingComboBox->currentIndex()).toInt();
+ QTextCodec *codec = QTextCodec::codecForMib(mib);
+
+ QTextStream in(&encodedData);
+ in.setAutoDetectUnicode(false);
+ in.setCodec(codec);
+ decodedStr = in.readAll();
+
+ textEdit->setPlainText(decodedStr);
+}
diff --git a/examples/tools/codecs/previewform.h b/examples/tools/codecs/previewform.h
new file mode 100644
index 0000000000..21a2e13722
--- /dev/null
+++ b/examples/tools/codecs/previewform.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PREVIEWFORM_H
+#define PREVIEWFORM_H
+
+#include <QDialog>
+#include <QList>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QLabel;
+class QTextCodec;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class PreviewForm : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PreviewForm(QWidget *parent = 0);
+
+ void setCodecList(const QList<QTextCodec *> &list);
+ void setEncodedData(const QByteArray &data);
+ QString decodedString() const { return decodedStr; }
+
+private slots:
+ void updateTextEdit();
+
+private:
+ QByteArray encodedData;
+ QString decodedStr;
+
+ QComboBox *encodingComboBox;
+ QLabel *encodingLabel;
+ QTextEdit *textEdit;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif
diff --git a/examples/tools/completer/completer.pro b/examples/tools/completer/completer.pro
new file mode 100644
index 0000000000..8c389e4b24
--- /dev/null
+++ b/examples/tools/completer/completer.pro
@@ -0,0 +1,14 @@
+HEADERS = fsmodel.h \
+ mainwindow.h
+SOURCES = fsmodel.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = completer.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/completer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS completer.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/completer
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/completer/completer.qrc b/examples/tools/completer/completer.qrc
new file mode 100644
index 0000000000..4f57e1a824
--- /dev/null
+++ b/examples/tools/completer/completer.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/countries.txt</file>
+ <file>resources/wordlist.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/completer/fsmodel.cpp b/examples/tools/completer/fsmodel.cpp
new file mode 100644
index 0000000000..645017f099
--- /dev/null
+++ b/examples/tools/completer/fsmodel.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "fsmodel.h"
+
+//! [0]
+FileSystemModel::FileSystemModel(QObject *parent)
+ : QFileSystemModel(parent)
+{
+}
+//! [0]
+
+//! [1]
+QVariant FileSystemModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole && index.column() == 0) {
+ QString path = QDir::toNativeSeparators(filePath(index));
+ if (path.endsWith(QDir::separator()))
+ path.chop(1);
+ return path;
+ }
+
+ return QFileSystemModel::data(index, role);
+}
+
+//! [1]
diff --git a/examples/tools/completer/fsmodel.h b/examples/tools/completer/fsmodel.h
new file mode 100644
index 0000000000..f9a59b2a3d
--- /dev/null
+++ b/examples/tools/completer/fsmodel.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FILESYSTEMMODEL_H
+#define FILESYSTEMMODEL_H
+
+#include <QFileSystemModel>
+
+// With a QFileSystemModel, set on a view, you will see "Program Files" in the view
+// But with this model, you will see "C:\Program Files" in the view.
+// We acheive this, by having the data() return the entire file path for
+// the display role. Note that the Qt::EditRole over which the QCompleter
+// looks for matches is left unchanged
+//! [0]
+class FileSystemModel : public QFileSystemModel
+{
+public:
+ FileSystemModel(QObject *parent = 0);
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/completer/main.cpp b/examples/tools/completer/main.cpp
new file mode 100644
index 0000000000..6edd7406c2
--- /dev/null
+++ b/examples/tools/completer/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(completer);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/completer/mainwindow.cpp b/examples/tools/completer/mainwindow.cpp
new file mode 100644
index 0000000000..8c848615dc
--- /dev/null
+++ b/examples/tools/completer/mainwindow.cpp
@@ -0,0 +1,281 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "fsmodel.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0), lineEdit(0)
+{
+ createMenu();
+
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *modelLabel = new QLabel;
+ modelLabel->setText(tr("Model"));
+
+ modelCombo = new QComboBox;
+ modelCombo->addItem(tr("QFileSytemModel"));
+ modelCombo->addItem(tr("QFileSytemModel that shows full path"));
+ modelCombo->addItem(tr("Country list"));
+ modelCombo->addItem(tr("Word list"));
+ modelCombo->setCurrentIndex(0);
+
+ QLabel *modeLabel = new QLabel;
+ modeLabel->setText(tr("Completion Mode"));
+ modeCombo = new QComboBox;
+ modeCombo->addItem(tr("Inline"));
+ modeCombo->addItem(tr("Filtered Popup"));
+ modeCombo->addItem(tr("Unfiltered Popup"));
+ modeCombo->setCurrentIndex(1);
+
+ QLabel *caseLabel = new QLabel;
+ caseLabel->setText(tr("Case Sensitivity"));
+ caseCombo = new QComboBox;
+ caseCombo->addItem(tr("Case Insensitive"));
+ caseCombo->addItem(tr("Case Sensitive"));
+ caseCombo->setCurrentIndex(0);
+//! [0]
+
+//! [1]
+ QLabel *maxVisibleLabel = new QLabel;
+ maxVisibleLabel->setText(tr("Max Visible Items"));
+ maxVisibleSpinBox = new QSpinBox;
+ maxVisibleSpinBox->setRange(3,25);
+ maxVisibleSpinBox->setValue(10);
+
+ wrapCheckBox = new QCheckBox;
+ wrapCheckBox->setText(tr("Wrap around completions"));
+ wrapCheckBox->setChecked(true);
+//! [1]
+
+//! [2]
+ contentsLabel = new QLabel;
+ contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+ connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel()));
+ connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
+ connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+ connect(maxVisibleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeMaxVisible(int)));
+//! [2]
+
+//! [3]
+ lineEdit = new QLineEdit;
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(modelLabel, 0, 0); layout->addWidget(modelCombo, 0, 1);
+ layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1);
+ layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1);
+ layout->addWidget(maxVisibleLabel, 3, 0); layout->addWidget(maxVisibleSpinBox, 3, 1);
+ layout->addWidget(wrapCheckBox, 4, 0);
+ layout->addWidget(contentsLabel, 5, 0, 1, 2);
+ layout->addWidget(lineEdit, 6, 0, 1, 2);
+ centralWidget->setLayout(layout);
+ setCentralWidget(centralWidget);
+
+ changeModel();
+
+ setWindowTitle(tr("Completer"));
+ lineEdit->setFocus();
+}
+//! [3]
+
+//! [4]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [4]
+
+//! [5]
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+//! [5]
+
+//! [6]
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+//! [6]
+
+//! [7]
+ if (!fileName.contains(QLatin1String("countries.txt")))
+ return new QStringListModel(words, completer);
+//! [7]
+
+ // The last two chars of the countries.txt file indicate the country
+ // symbol. We put that in column 2 of a standard item model
+//! [8]
+ QStandardItemModel *m = new QStandardItemModel(words.count(), 2, completer);
+//! [8] //! [9]
+ for (int i = 0; i < words.count(); ++i) {
+ QModelIndex countryIdx = m->index(i, 0);
+ QModelIndex symbolIdx = m->index(i, 1);
+ QString country = words[i].mid(0, words[i].length() - 2).trimmed();
+ QString symbol = words[i].right(2);
+ m->setData(countryIdx, country);
+ m->setData(symbolIdx, symbol);
+ }
+
+ return m;
+}
+//! [9]
+
+//! [10]
+void MainWindow::changeMode(int index)
+{
+ QCompleter::CompletionMode mode;
+ if (index == 0)
+ mode = QCompleter::InlineCompletion;
+ else if (index == 1)
+ mode = QCompleter::PopupCompletion;
+ else
+ mode = QCompleter::UnfilteredPopupCompletion;
+
+ completer->setCompletionMode(mode);
+}
+//! [10]
+
+void MainWindow::changeCase(int cs)
+{
+ completer->setCaseSensitivity(cs ? Qt::CaseSensitive : Qt::CaseInsensitive);
+}
+
+//! [11]
+void MainWindow::changeModel()
+{
+ delete completer;
+ completer = new QCompleter(this);
+ completer->setMaxVisibleItems(maxVisibleSpinBox->value());
+
+ switch (modelCombo->currentIndex()) {
+ default:
+ case 0:
+ { // Unsorted QFileSystemModel
+ QFileSystemModel *fsModel = new QFileSystemModel(completer);
+ fsModel->setRootPath("");
+ completer->setModel(fsModel);
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [11] //! [12]
+ case 1:
+ { // FileSystemModel that shows full paths
+ FileSystemModel *fsModel = new FileSystemModel(completer);
+ completer->setModel(fsModel);
+ fsModel->setRootPath("");
+ contentsLabel->setText(tr("Enter file path"));
+ }
+ break;
+//! [12] //! [13]
+ case 2:
+ { // Country List
+ completer->setModel(modelFromFile(":/resources/countries.txt"));
+ QTreeView *treeView = new QTreeView;
+ completer->setPopup(treeView);
+ treeView->setRootIsDecorated(false);
+ treeView->header()->hide();
+ treeView->header()->setStretchLastSection(false);
+ treeView->header()->setResizeMode(0, QHeaderView::Stretch);
+ treeView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
+ contentsLabel->setText(tr("Enter name of your country"));
+ }
+ break;
+//! [13] //! [14]
+ case 3:
+ { // Word list
+ completer->setModel(modelFromFile(":/resources/wordlist.txt"));
+ completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+ contentsLabel->setText(tr("Enter a word"));
+ }
+ break;
+ }
+
+ changeMode(modeCombo->currentIndex());
+ changeCase(caseCombo->currentIndex());
+ completer->setWrapAround(wrapCheckBox->isChecked());
+ lineEdit->setCompleter(completer);
+ connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+}
+//! [14]
+
+//! [15]
+void MainWindow::changeMaxVisible(int max)
+{
+ completer->setMaxVisibleItems(max);
+}
+//! [15]
+
+//! [16]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [16]
diff --git a/examples/tools/completer/mainwindow.h b/examples/tools/completer/mainwindow.h
new file mode 100644
index 0000000000..e22a32d83e
--- /dev/null
+++ b/examples/tools/completer/mainwindow.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+class QSpinBox;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+ void changeCase(int);
+ void changeMode(int);
+ void changeModel();
+ void changeMaxVisible(int);
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QComboBox *modelCombo;
+ QSpinBox *maxVisibleSpinBox;
+ QCheckBox *wrapCheckBox;
+ QCompleter *completer;
+ QLabel *contentsLabel;
+ QLineEdit *lineEdit;
+};
+//! [1]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/completer/resources/countries.txt b/examples/tools/completer/resources/countries.txt
new file mode 100644
index 0000000000..5854fbc977
--- /dev/null
+++ b/examples/tools/completer/resources/countries.txt
@@ -0,0 +1,241 @@
+Afghanistan AF
+Albania AL
+Algeria DZ
+American Samoa AS
+Andorra AD
+Angola AO
+Anguilla AI
+Antarctica AQ
+Antigua And Barbuda AG
+Argentina AR
+Armenia AM
+Aruba AW
+Australia AU
+Austria AT
+Azerbaijan AZ
+Bahamas BS
+Bahrain BH
+Bangladesh BD
+Barbados BB
+Belarus BY
+Belgium BE
+Belize BZ
+Benin BJ
+Bermuda BM
+Bhutan BT
+Bolivia BO
+Bosnia And Herzegowina BA
+Botswana BW
+Bouvet Island BV
+Brazil BR
+British Indian Ocean Territory IO
+British Virgin Islands VG
+Brunei Darussalam BN
+Bulgaria BG
+Burkina Faso BF
+Burundi BI
+Cambodia KH
+Cameroon CM
+Canada CA
+Cape Verde CV
+Cayman Islands KY
+Central African Republic CF
+Chad TD
+Chile CL
+China CN
+Christmas Island CX
+Cocos Islands CC
+Colombia CO
+Comoros KM
+Cook Islands CK
+Costa Rica CR
+Croatia HR
+Cuba CU
+Cyprus CY
+Czech Republic CZ
+Democratic Republic Of Congo CD
+Democratic Republic Of Korea KP
+Denmark DK
+Djibouti DJ
+Dominica DM
+Dominican Republic DO
+EastTimor TL
+Ecuador EC
+Egypt EG
+El Salvador SV
+Equatorial Guinea GQ
+Eritrea ER
+Estonia EE
+Ethiopia ET
+Falkland Islands FK
+Faroe Islands FO
+Fiji FJ
+Finland FI
+France FR
+French Guiana GF
+French Polynesia PF
+French Southern Territories TF
+Gabon GA
+Gambia GM
+Georgia GE
+Germany DE
+Ghana GH
+Gibraltar GI
+Greece GR
+Greenland GL
+Grenada GD
+Guadeloupe GP
+Guam GU
+Guatemala GT
+Guinea GN
+Guinea Bissau GW
+Guyana GY
+Haiti HT
+Heard And McDonald Islands HM
+Honduras HN
+Hong Kong HK
+Hungary HU
+Iceland IS
+India IN
+Indonesia ID
+Iran IR
+Iraq IQ
+Ireland IE
+Israel IL
+Italy IT
+Ivory Coast CI
+Jamaica JM
+Japan JP
+Jordan JO
+Kazakhstan KZ
+Kenya KE
+Kiribati KI
+Kuwait KW
+Kyrgyzstan KG
+Lao LA
+Latvia LV
+Lebanon LB
+Lesotho LS
+Liberia LR
+Libyan Arab Jamahiriya LY
+Liechtenstein LI
+Lithuania LT
+Luxembourg LU
+Macau MO
+Macedonia MK
+Madagascar MG
+Malawi MW
+Malaysia MY
+Maldives MV
+Mali ML
+Malta MT
+Marshall Islands MH
+Martinique MQ
+Mauritania MR
+Mauritius MU
+Mayotte YT
+Metropolitan France FX
+Mexico MX
+Micronesia FM
+Moldova MD
+Monaco MC
+Mongolia MN
+Montserrat MS
+Morocco MA
+Mozambique MZ
+Myanmar MM
+Namibia NA
+Nauru NR
+Nepal NP
+Netherlands NL
+Netherlands Antilles AN
+New Caledonia NC
+New Zealand NZ
+Nicaragua NI
+Niger NE
+Nigeria NG
+Niue NU
+Norfolk Island NF
+Northern Mariana Islands MP
+Norway NO
+Oman OM
+Pakistan PK
+Palau PW
+Palestinian Territory PS
+Panama PA
+Papua New Guinea PG
+Paraguay PY
+Peoples Republic Of Congo CG
+Peru PE
+Philippines PH
+Pitcairn PN
+Poland PL
+Portugal PT
+Puerto Rico PR
+Qatar QA
+Republic Of Korea KR
+Reunion RE
+Romania RO
+Russian Federation RU
+Rwanda RW
+Saint Kitts And Nevis KN
+Samoa WS
+San Marino SM
+Sao Tome And Principe ST
+Saudi Arabia SA
+Senegal SN
+Serbia And Montenegro CS
+Seychelles SC
+Sierra Leone SL
+Singapore SG
+Slovakia SK
+Slovenia SI
+Solomon Islands SB
+Somalia SO
+South Africa ZA
+South Georgia And The South Sandwich Islands GS
+Spain ES
+Sri Lanka LK
+St Helena SH
+St Lucia LC
+St Pierre And Miquelon PM
+St Vincent And The Grenadines VC
+Sudan SD
+Suriname SR
+Svalbard And Jan Mayen Islands SJ
+Swaziland SZ
+Sweden SE
+Switzerland CH
+Syrian Arab Republic SY
+Taiwan TW
+Tajikistan TJ
+Tanzania TZ
+Thailand TH
+Togo TG
+Tokelau TK
+Tonga TO
+Trinidad And Tobago TT
+Tunisia TN
+Turkey TR
+Turkmenistan TM
+Turks And Caicos Islands TC
+Tuvalu TV
+US Virgin Islands VI
+Uganda UG
+Ukraine UA
+United Arab Emirates AE
+United Kingdom GB
+United States US
+United States Minor Outlying Islands UM
+Uruguay UY
+Uzbekistan UZ
+Vanuatu VU
+Vatican City State VA
+Venezuela VE
+Viet Nam VN
+Wallis And Futuna Islands WF
+Western Sahara EH
+Yemen YE
+Yugoslavia YU
+Zambia ZM
+Zimbabwe ZW
diff --git a/examples/tools/completer/resources/wordlist.txt b/examples/tools/completer/resources/wordlist.txt
new file mode 100644
index 0000000000..1f56e36d47
--- /dev/null
+++ b/examples/tools/completer/resources/wordlist.txt
@@ -0,0 +1,1485 @@
+A4
+able
+about
+above
+absence
+absolutely
+abstract
+access
+according
+accumulated
+achieve
+achieving
+activity
+acts
+actual
+actually
+add
+added
+adding
+addition
+additionally
+additions
+addresses
+adjust
+adjustments
+advanced
+advice
+after
+afterwards
+again
+agenda
+aim
+algorithm
+all
+allocated
+allow
+allowed
+allowing
+allows
+along
+alpha
+already
+also
+alternative
+alternatively
+although
+American
+an
+and
+announced
+annoy
+another
+answer
+answers
+any
+anything
+anyway
+apart
+API
+appear
+appears
+appendices
+appendix
+appends
+application
+applications
+apply
+approach
+approaches
+appropriate
+Arabic
+arbitrary
+are
+areas
+ARGB
+argument
+arguments
+around
+arrangements
+arrive
+arrived
+Arthur
+article
+articles
+as
+asked
+aspects
+assume
+at
+attachment
+attempt
+attempting
+attend
+attendees
+attributes
+authors
+auto-detect
+auto-detecting
+availability
+available
+avoid
+away
+back
+background
+backgrounds
+bandwidth
+bandwidths
+Barcelona
+base
+based
+basic
+basically
+basics
+be
+because
+been
+before
+behave
+behavior
+behind
+being
+below
+benefits
+Berkeley
+between
+bit
+bits
+bitwise
+black
+blended
+blending
+blends
+block
+blue
+BMP
+body
+bold
+booking
+bool
+Boston
+both
+bottom
+box
+boxes
+braces
+break
+breaks
+broad
+browsers
+buffer
+buffers
+build
+builds
+built
+bundled
+burdens
+busy
+but
+by
+bypass
+bypassing
+bytes
+calendar
+call
+called
+calling
+calls
+Cambridge
+can
+canonical
+canonicalised
+cap
+capabilities
+capacity
+caption
+card
+care
+case
+cast
+catch
+causing
+centre
+certain
+challenges
+chance
+change
+changes
+changing
+channel
+channels
+chapter
+char
+chart
+charts
+check
+checks
+Chicago
+chit-chat
+chosen
+chunk
+circle
+citation
+city
+claim
+class
+classes
+clause
+clauses
+clear
+clearing
+client
+clients
+close
+closed
+co-author
+code
+colon
+color
+color-coded
+colorize
+colorizer
+colors
+colour
+column
+columns
+combine
+combined
+combines
+combining
+comes
+command
+commands
+comment
+common
+communicate
+community
+compiled
+complement
+complete
+completely
+completeness
+completes
+completion
+complex
+compliant
+component
+components
+compositing
+composition
+compression
+computation
+computer
+concepts
+conclusion
+concurrent
+configurable
+congested
+congestion
+connect
+connected
+connection
+connections
+cons
+consider
+consisting
+consists
+construct
+constructed
+constructing
+constructor
+constructs
+consume
+contact
+contain
+containing
+contains
+contents
+contents
+continue
+continued
+contributors
+control
+controlled
+controller
+controller
+controlling
+controls
+controls
+conventions
+cook
+cooperation
+copy
+copyright
+core
+cores
+corollary
+correct
+correctly
+corresponding
+could
+couple
+coworkers
+CPU
+create
+creates
+creating
+cross-platform
+crucial
+cultures
+current
+currently
+custom
+customized
+cut
+data
+database
+datasets
+datum
+day
+days
+deal
+dealing
+decide
+decouple
+decoupled
+deeply
+def
+default
+define
+defines
+definition
+definitions
+delegate
+delete
+demo
+demonstrate
+demonstrations
+deployed
+describe
+describes
+design
+desktop
+desktops
+destination
+destinations
+destructor
+details
+detect
+determine
+determines
+developer
+developers
+development
+developments
+device
+devices
+diagram
+dialogs
+dictionary
+did
+difference
+differences
+different
+differs
+digital
+direct
+direct
+directions
+directly
+directory
+discuss
+display
+displaying
+displays
+distribute
+distribution
+disturbing
+divide
+do
+documentation
+documents
+does
+done
+down
+downLimit
+download
+downloaded
+downloading
+draw
+drawing
+drawn
+drop
+drop-in
+Duff
+during
+DVD
+dynamic
+dynamically
+dynamics
+each
+earlier
+easily
+editing
+editors
+education
+effect
+effectively
+effects
+either
+ellipse
+ellipses
+elliptical
+else
+email
+e-mail
+embedded
+emit
+emits
+empty
+enable
+enables
+encapsulates
+enclose
+end
+endnote
+endnotes
+end-user
+engineer
+engineering
+English
+enjoys
+enough
+ensure
+ensures
+entails
+enter
+entire
+entitled
+entries
+entry
+environment
+erases
+error
+errors
+especially
+established
+etc.
+Europe
+even
+evenly
+event
+events
+eventually
+every
+everyone
+example
+examples
+except
+exception
+excessive
+exclusive
+existing
+exists
+expand
+expected
+expense
+export
+exposes
+extend
+extended
+extending
+extensible
+extension
+external
+extra
+extract
+faces
+facilities
+factory
+fade
+failure
+fairness
+falls
+false
+family
+fashion
+fast
+faster
+features
+February
+feedback
+feel
+fetch
+fetching
+few
+fields
+figure
+figures
+file
+file name
+files
+filled
+filler
+final
+finally
+find
+fine
+finish
+finished
+first
+flow
+fly
+focus
+followed
+following
+font
+foot
+footnote
+footnotes
+for
+form
+format
+formats
+format-specific
+forms
+formula
+formulas
+forum
+found
+framework
+France
+from
+front
+full
+fully
+function
+functionality
+function-based
+functions
+future
+gain
+games
+gap
+general
+generic
+Germany
+get
+gill
+give
+given
+gives
+giving
+global
+go
+goes
+got
+gradient
+gradient-filled
+graph
+graphical
+graphics
+gray
+great
+greatly
+green
+grey
+group
+growing
+gui
+GUI
+hack
+had
+half
+Hamburg
+hand
+handing
+handle
+handler
+handlers
+handles
+handling
+happens
+hardware
+harmonica
+has
+have
+having
+he
+head
+header
+headers
+hear
+height
+help
+helper
+here
+high
+high-complexity
+high-level
+highlight
+highly
+hints
+his
+hold
+holder
+holding
+hole
+home
+horizontal
+host
+hosting
+hours
+Houston
+how
+however
+huge
+hyphen
+ID
+idea
+ideally
+if
+Illinois
+illustrate
+illustrated
+illustrates
+image
+images
+impact
+implement
+implementation
+implementations
+implemented
+implementing
+implements
+import
+important
+improvements
+in
+include
+included
+includes
+including
+inclusion
+incoming
+inconvenient
+indent
+index
+indicate
+inexpensively
+influence
+info
+information
+ingenious
+inherits
+initial
+initially
+inner
+input
+inspired
+install
+installs
+instance
+instead
+instructs
+integer
+integers
+integration
+intended
+intensive
+interest
+interests
+interface
+interfaces
+interfere
+internal
+interval
+into
+intriguing
+intro
+introduce
+introduced
+invalid
+invented
+inverse
+invocation
+involved
+Irish
+irregular
+is
+ISO
+ISPs
+issue
+issues
+it
+items
+iterate
+its
+itself
+job
+join
+JPEG
+jungle
+just
+Karaoke
+keep
+keeping
+key
+kind
+king
+known
+label
+labels
+landscape
+language
+large
+last
+later
+latest
+lawn
+layout
+lead
+leader
+leaders
+lean
+leaves
+leaving
+left
+lemma
+length
+less
+let
+level
+levels
+libraries
+library
+lies
+like
+likely
+limit
+limiting
+limits
+line
+linear
+lines
+linewidth
+link
+linked
+linking
+Linux
+list
+lists
+little
+lives
+load
+loading
+loads
+located
+location
+locations
+logo
+long
+longer
+look
+looked
+looking
+looks
+lookup
+lookups
+loop
+lout
+low
+lower-case
+low-level
+macro
+made
+magazine
+magic
+main
+major
+make
+makes
+making
+manage
+managed
+managing
+mandatory
+manipulate
+manipulation
+manner
+many
+map
+maps
+March
+margin
+mask
+masking
+Massachusetts
+match
+mathematical
+maximum
+may
+means
+meet
+member
+members
+memory
+merged
+method
+might
+milliseconds
+minimize
+minimum
+minor
+mix
+MNG
+mode
+model
+models
+modes
+modified
+module
+moments
+monitored
+monthly
+more
+most
+mostly
+move
+much
+multitude
+Munich
+must
+name
+named
+names
+necessary
+need
+needed
+needs
+network
+new
+news
+newsletter
+next
+nicely
+no
+none
+non-Qt
+non-trivial
+non-zero
+normally
+Norway
+not
+note
+notes
+nothing
+notifies
+notify
+now
+null
+number
+numbered
+numbering
+numbers
+Nydalen
+object
+objects
+obtain
+obtaining
+odd
+of
+off
+office
+offset
+offsets
+often
+old
+on
+once
+one
+ones
+online
+only
+on-screen
+onto
+opacity
+opaque
+open
+opens
+operates
+operating
+operation
+operations
+operator
+opportunity
+opposed
+optimize
+option
+optionally
+options
+or
+OR
+order
+ordinary
+original
+originally
+Oslo
+other
+otherwise
+our
+out
+outer
+outgoing
+output
+outside
+over
+overcoming
+overrides
+overview
+own
+owner
+owners
+pace
+Pacific
+package
+packages
+packets
+page
+pages
+paint
+painted
+painting
+paragraph
+paragraphs
+parameters
+parent
+Paris
+parse
+part
+partial
+partially
+particular
+partners
+parts
+party
+passed
+passing
+patches
+path
+pattern
+patterns
+pause
+PDF
+peek
+pending
+perform
+performed
+performs
+permission
+permutations
+personal
+pick
+pie
+pipe
+pixel
+pixels
+place
+places
+planning
+platform-independent
+platforms
+play
+players
+playing
+please
+pleasing
+plugin
+plugin-enabled
+plugins
+plus
+PNG
+pointer
+pop
+popular
+populates
+porter
+Porter
+portrait
+possibility
+possible
+potential
+potentially
+power
+powers
+preceded
+presence
+present
+prevent
+prevents
+previous
+previously
+primarily
+primary
+primitives
+printed
+printing
+prior
+probably
+problem
+process
+processes
+processing
+produce
+produced
+produces
+products
+programming
+programs
+project
+projects
+proof
+proper
+properly
+properties
+property
+proposed
+proposition
+pros
+protocols
+proud
+provide
+provided
+provides
+provision
+proxy
+public
+published
+punch
+punches
+pursuing
+put
+Qt
+Qtopia
+Qt-related
+quality
+quarter
+quarterly
+queried
+queries
+query
+question
+questions
+radial
+ragged
+range
+rate
+rate-controlled
+rates
+rather
+ratio
+raw
+read
+reader
+reading
+reads
+ready
+real
+realistic
+really
+real-time
+received
+recent
+recognized
+recommended
+recompile
+rectangle
+rectangular
+red
+redistribute
+reducing
+reference
+references
+reflect
+regardless
+regional
+register
+registered
+registration
+reimplement
+reimplementation
+reimplemented
+release
+released
+releases
+reliable
+rely
+remains
+remember
+removed
+removes
+repeatedly
+replace
+report
+represent
+represented
+represents
+reproduced
+requested
+require
+required
+requires
+resetting
+resides
+resolve
+respective
+respectively
+response
+rest
+restart
+result
+resulting
+resume
+return
+returning
+returns
+reuse
+revealing
+rich
+riches
+right
+roadshow
+role
+Roman
+round-trip
+router
+routers
+rule
+run
+runner
+runners
+running
+runs
+run-time
+sake
+sales
+salespeople
+same
+sample
+San Jose
+save
+saved
+saves
+say
+scalable
+scale
+scanline
+scanline-level
+scene
+scenes
+schedule
+school
+script
+seam
+seamless
+search
+searches
+searching
+second
+seconds
+section
+sections
+security
+see
+seen
+selection
+seminar
+seminars
+sending
+separated
+separates
+series
+service
+services
+set
+setting
+setup
+seven
+seventh
+several
+shade
+shadow
+shape
+shares
+shaves
+shine
+shorter
+should
+show
+shown
+shows
+side
+signal
+signals
+signature
+significantly
+similar
+similarily
+similarly
+simple
+simplest
+simplified
+simplifying
+simply
+simulate
+simultaneous
+since
+single
+size
+sizes
+slightly
+slope
+slot
+slowing
+small
+smaller
+so
+socket
+sockets
+software
+solutions
+solved
+some
+soon
+sort
+sorting
+source
+sources
+south
+space
+special
+specialized
+specific
+specifically
+specification
+specifications
+specified
+specify
+speed
+spend
+split
+SQL
+standard
+standards
+start
+starts
+starve
+state
+states
+static
+steady
+stealing
+step
+still
+stop
+stopwatch
+store
+stored
+stores
+straightforward
+stream
+string
+strings
+structure
+structured
+strut
+style
+styles
+styling
+subclass
+subclassing
+subdirectory
+subsection
+subsections
+succeeds
+success
+successful
+successfully
+such
+suggestion
+suggestions
+suitable
+support
+supported
+supports
+suppose
+supposes
+sure
+switch
+switches
+symbol
+symbols
+synonyms
+system
+systems
+table
+tables
+tags
+take
+takes
+tap
+target
+targets
+TCP
+team
+technically-focused
+technique
+technology
+template
+templates
+Texas
+text
+than
+that
+the
+their
+them
+then
+theorem
+there
+these
+they
+thickness
+thin
+third
+this
+those
+three
+throttling
+through
+tightly
+time
+timer
+times
+tiny
+tips
+title
+titles
+to
+together
+too
+top
+torrent
+total
+tour
+trademarks
+traffic
+training
+transaction
+transfer
+transferred
+transferring
+transfers
+translucency
+translucent
+transparency
+transparent
+travel
+traveled
+true
+try
+turn
+twice
+two
+type
+typed
+typical
+typically
+unable
+under
+underlying
+understanding
+undoes
+unique
+united
+unlike
+unpack
+unsigned
+until
+untouched
+up
+update
+updated
+updates
+upload
+uploading
+uploads
+up-to-date
+us
+use
+used
+useful
+user
+user-friendly
+users
+uses
+using
+usual
+usually
+valid
+value
+values
+variable
+variation
+variety
+various
+vector
+venturing
+verifying
+versa
+version
+versions
+vertical
+very
+via
+vice
+virtual
+visual
+void
+VP
+waiting
+Wales
+want
+wants
+was
+way
+ways
+we
+web
+website
+well
+were
+what
+when
+whenever
+where
+whether
+which
+while
+whistle
+white
+who
+whole
+why
+widget
+widgets
+width
+widths
+will
+window
+windows
+wish
+with
+without
+word
+words
+work
+working
+works
+would
+wrap
+wrapper
+write
+writes
+writing
+writings
+written
+X
+X11
+XOR
+year
+years
+yes
+you
+your
+zero
diff --git a/examples/tools/contiguouscache/contiguouscache.pro b/examples/tools/contiguouscache/contiguouscache.pro
new file mode 100644
index 0000000000..45166d380e
--- /dev/null
+++ b/examples/tools/contiguouscache/contiguouscache.pro
@@ -0,0 +1,9 @@
+HEADERS = randomlistmodel.h
+SOURCES = randomlistmodel.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/contiguouscache
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS contiguouscache.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/contiguouscache
+INSTALLS += target sources
diff --git a/examples/tools/contiguouscache/main.cpp b/examples/tools/contiguouscache/main.cpp
new file mode 100644
index 0000000000..d578a389bf
--- /dev/null
+++ b/examples/tools/contiguouscache/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "randomlistmodel.h"
+#include <QListView>
+#include <QApplication>
+
+int main(int c, char **v)
+{
+ QApplication a(c, v);
+
+ QListView view;
+ view.setUniformItemSizes(true);
+ view.setModel(new RandomListModel(&view));
+ view.show();
+
+ return a.exec();
+}
diff --git a/examples/tools/contiguouscache/randomlistmodel.cpp b/examples/tools/contiguouscache/randomlistmodel.cpp
new file mode 100644
index 0000000000..845b1e7a2a
--- /dev/null
+++ b/examples/tools/contiguouscache/randomlistmodel.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "randomlistmodel.h"
+#include <stdlib.h>
+
+static const int bufferSize(500);
+static const int lookAhead(100);
+static const int halfLookAhead(lookAhead/2);
+
+RandomListModel::RandomListModel(QObject *parent)
+: QAbstractListModel(parent), m_rows(bufferSize), m_count(10000)
+{
+}
+
+RandomListModel::~RandomListModel()
+{
+}
+
+int RandomListModel::rowCount(const QModelIndex &) const
+{
+ return m_count;
+}
+
+//! [0]
+QVariant RandomListModel::data(const QModelIndex &index, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ int row = index.row();
+
+ if (row > m_rows.lastIndex()) {
+ if (row - m_rows.lastIndex() > lookAhead)
+ cacheRows(row-halfLookAhead, qMin(m_count, row+halfLookAhead));
+ else while (row > m_rows.lastIndex())
+ m_rows.append(fetchRow(m_rows.lastIndex()+1));
+ } else if (row < m_rows.firstIndex()) {
+ if (m_rows.firstIndex() - row > lookAhead)
+ cacheRows(qMax(0, row-halfLookAhead), row+halfLookAhead);
+ else while (row < m_rows.firstIndex())
+ m_rows.prepend(fetchRow(m_rows.firstIndex()-1));
+ }
+
+ return m_rows.at(row);
+}
+
+void RandomListModel::cacheRows(int from, int to) const
+{
+ for (int i = from; i <= to; ++i)
+ m_rows.insert(i, fetchRow(i));
+}
+//![0]
+
+//![1]
+QString RandomListModel::fetchRow(int position) const
+{
+ return QString::number(rand() % ++position);
+}
+//![1]
diff --git a/examples/tools/contiguouscache/randomlistmodel.h b/examples/tools/contiguouscache/randomlistmodel.h
new file mode 100644
index 0000000000..96a4dc0c8b
--- /dev/null
+++ b/examples/tools/contiguouscache/randomlistmodel.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 RANDOMLISTMODEL_H
+#define RANDOMLISTMODEL_H
+
+#include <QContiguousCache>
+#include <QAbstractListModel>
+
+class QTimer;
+class RandomListModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ RandomListModel(QObject *parent = 0);
+ ~RandomListModel();
+
+ int rowCount(const QModelIndex & = QModelIndex()) const;
+ QVariant data(const QModelIndex &, int) const;
+
+private:
+ void cacheRows(int, int) const;
+ QString fetchRow(int) const;
+
+ mutable QContiguousCache<QString> m_rows;
+ const int m_count;
+};
+
+#endif
diff --git a/examples/tools/customcompleter/customcompleter.pro b/examples/tools/customcompleter/customcompleter.pro
new file mode 100644
index 0000000000..9af70c06d0
--- /dev/null
+++ b/examples/tools/customcompleter/customcompleter.pro
@@ -0,0 +1,14 @@
+HEADERS = mainwindow.h \
+ textedit.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ textedit.cpp
+RESOURCES = customcompleter.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/customcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS customcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/customcompleter
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/customcompleter/customcompleter.qrc b/examples/tools/customcompleter/customcompleter.qrc
new file mode 100644
index 0000000000..d7da1bf9a6
--- /dev/null
+++ b/examples/tools/customcompleter/customcompleter.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/wordlist.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/customcompleter/main.cpp b/examples/tools/customcompleter/main.cpp
new file mode 100644
index 0000000000..2024f50a85
--- /dev/null
+++ b/examples/tools/customcompleter/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(customcompleter);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/customcompleter/mainwindow.cpp b/examples/tools/customcompleter/mainwindow.cpp
new file mode 100644
index 0000000000..c4a7c76e3b
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "mainwindow.h"
+#include "textedit.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0)
+{
+ createMenu();
+
+ completingTextEdit = new TextEdit;
+ completer = new QCompleter(this);
+ completer->setModel(modelFromFile(":/resources/wordlist.txt"));
+ completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
+ completer->setCaseSensitivity(Qt::CaseInsensitive);
+ completer->setWrapAround(false);
+ completingTextEdit->setCompleter(completer);
+
+ setCentralWidget(completingTextEdit);
+ resize(500, 300);
+ setWindowTitle(tr("Completer"));
+}
+//! [0]
+
+//! [1]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [1]
+
+//! [2]
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine();
+ if (!line.isEmpty())
+ words << line.trimmed();
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+ return new QStringListModel(words, completer);
+}
+//! [2]
+
+//! [3]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates the "
+ "different features of the QCompleter class."));
+}
+//! [3]
+
diff --git a/examples/tools/customcompleter/mainwindow.h b/examples/tools/customcompleter/mainwindow.h
new file mode 100644
index 0000000000..b645984826
--- /dev/null
+++ b/examples/tools/customcompleter/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QCompleter;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+QT_END_NAMESPACE
+class TextEdit;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QCompleter *completer;
+ TextEdit *completingTextEdit;
+};
+//! [0]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/customcompleter/resources/wordlist.txt b/examples/tools/customcompleter/resources/wordlist.txt
new file mode 100644
index 0000000000..f8b581a405
--- /dev/null
+++ b/examples/tools/customcompleter/resources/wordlist.txt
@@ -0,0 +1,1454 @@
+A4
+able
+about
+above
+absence
+absolutely
+abstract
+access
+according
+accumulated
+achieve
+achieving
+activity
+acts
+actual
+actually
+add
+added
+adding
+addition
+additionally
+additions
+addresses
+adjust
+adjustments
+advanced
+advice
+after
+afterwards
+again
+agenda
+aim
+algorithm
+all
+allocated
+allow
+allowed
+allowing
+allows
+along
+alpha
+already
+also
+alternative
+alternatively
+although
+American
+an
+and
+announced
+annoy
+another
+answer
+answers
+any
+anything
+anyway
+apart
+API
+appear
+appears
+appendices
+appendix
+appends
+application
+applications
+apply
+approach
+approaches
+appropriate
+Arabic
+arbitrary
+are
+areas
+ARGB
+argument
+arguments
+around
+arrangements
+arrive
+arrived
+Arthur
+article
+articles
+as
+asked
+aspects
+assume
+at
+attachment
+attempt
+attempting
+attend
+attendees
+attributes
+authors
+availability
+available
+avoid
+away
+back
+background
+backgrounds
+bandwidth
+bandwidths
+Barcelona
+base
+based
+basic
+basically
+basics
+be
+because
+been
+before
+behave
+behavior
+behind
+being
+below
+benefits
+Berkeley
+between
+bit
+bits
+bitwise
+black
+blended
+blending
+blends
+block
+blue
+BMP
+body
+bold
+booking
+bool
+Boston
+both
+bottom
+box
+boxes
+braces
+break
+breaks
+broad
+browsers
+buffer
+buffers
+build
+builds
+built
+bundled
+burdens
+busy
+but
+by
+bypass
+bypassing
+bytes
+calendar
+call
+called
+calling
+calls
+Cambridge
+can
+canonical
+canonicalised
+cap
+capabilities
+capacity
+caption
+card
+care
+case
+cast
+catch
+causing
+centre
+certain
+challenges
+chance
+change
+changes
+changing
+channel
+channels
+chapter
+char
+chart
+charts
+check
+checks
+Chicago
+chosen
+chunk
+circle
+citation
+city
+claim
+class
+classes
+clause
+clauses
+clear
+clearing
+client
+clients
+close
+closed
+code
+colon
+color
+colorize
+colorizer
+colors
+colour
+column
+columns
+combine
+combined
+combines
+combining
+comes
+command
+commands
+comment
+common
+communicate
+community
+compiled
+complement
+complete
+completely
+completeness
+completes
+completion
+complex
+compliant
+component
+components
+compositing
+composition
+compression
+computation
+computer
+concepts
+conclusion
+concurrent
+configurable
+congested
+congestion
+connect
+connected
+connection
+connections
+cons
+consider
+consisting
+consists
+construct
+constructed
+constructing
+constructor
+constructs
+consume
+contact
+contain
+containing
+contains
+contents
+contents
+continue
+continued
+contributors
+control
+controlled
+controller
+controller
+controlling
+controls
+controls
+conventions
+cook
+cooperation
+copy
+copyright
+core
+cores
+corollary
+correct
+correctly
+corresponding
+could
+couple
+coworkers
+CPU
+create
+creates
+creating
+crucial
+cultures
+current
+currently
+custom
+customized
+cut
+data
+database
+datasets
+datum
+day
+days
+deal
+dealing
+decide
+decouple
+decoupled
+deeply
+def
+default
+define
+defines
+definition
+definitions
+delegate
+delete
+demo
+demonstrate
+demonstrations
+deployed
+describe
+describes
+design
+desktop
+desktops
+destination
+destinations
+destructor
+details
+detect
+determine
+determines
+developer
+developers
+development
+developments
+device
+devices
+diagram
+dialogs
+dictionary
+did
+difference
+differences
+different
+differs
+digital
+direct
+direct
+directions
+directly
+directory
+discuss
+display
+displaying
+displays
+distribute
+distribution
+disturbing
+divide
+do
+documentation
+documents
+does
+done
+down
+downLimit
+download
+downloaded
+downloading
+draw
+drawing
+drawn
+drop
+Duff
+during
+DVD
+dynamic
+dynamically
+dynamics
+each
+earlier
+easily
+editing
+editors
+education
+effect
+effectively
+effects
+either
+ellipse
+ellipses
+elliptical
+else
+email
+embedded
+emit
+emits
+empty
+enable
+enables
+encapsulates
+enclose
+end
+endnote
+endnotes
+engineer
+engineering
+English
+enjoys
+enough
+ensure
+ensures
+entails
+enter
+entire
+entitled
+entries
+entry
+environment
+erases
+error
+errors
+especially
+established
+etc.
+Europe
+even
+evenly
+event
+events
+eventually
+every
+everyone
+example
+examples
+except
+exception
+excessive
+exclusive
+existing
+exists
+expand
+expected
+expense
+export
+exposes
+extend
+extended
+extending
+extensible
+extension
+external
+extra
+extract
+faces
+facilities
+factory
+fade
+failure
+fairness
+falls
+false
+family
+fashion
+fast
+faster
+features
+February
+feedback
+feel
+fetch
+fetching
+few
+fields
+figure
+figures
+file
+file name
+files
+filled
+filler
+final
+finally
+find
+fine
+finish
+finished
+first
+flow
+fly
+focus
+followed
+following
+font
+foot
+footnote
+footnotes
+for
+form
+format
+formats
+forms
+formula
+formulas
+forum
+found
+framework
+France
+from
+front
+full
+fully
+function
+functionality
+functions
+future
+gain
+games
+gap
+general
+generic
+Germany
+get
+gill
+give
+given
+gives
+giving
+global
+go
+goes
+got
+gradient
+graph
+graphical
+graphics
+gray
+great
+greatly
+green
+grey
+group
+growing
+gui
+GUI
+hack
+had
+half
+Hamburg
+hand
+handing
+handle
+handler
+handlers
+handles
+handling
+happens
+hardware
+harmonica
+has
+have
+having
+he
+head
+header
+headers
+hear
+height
+help
+helper
+here
+high
+highlight
+highly
+hints
+his
+hold
+holder
+holding
+hole
+home
+horizontal
+host
+hosting
+hours
+Houston
+how
+however
+huge
+hyphen
+ID
+idea
+ideally
+if
+Illinois
+illustrate
+illustrated
+illustrates
+image
+images
+impact
+implement
+implementation
+implementations
+implemented
+implementing
+implements
+import
+important
+improvements
+in
+include
+included
+includes
+including
+inclusion
+incoming
+inconvenient
+indent
+index
+indicate
+inexpensively
+influence
+info
+information
+ingenious
+inherits
+initial
+initially
+inner
+input
+inspired
+install
+installs
+instance
+instead
+instructs
+integer
+integers
+integration
+intended
+intensive
+interest
+interests
+interface
+interfaces
+interfere
+internal
+interval
+into
+intriguing
+intro
+introduce
+introduced
+invalid
+invented
+inverse
+invocation
+involved
+Irish
+irregular
+is
+ISO
+ISPs
+issue
+issues
+it
+items
+iterate
+its
+itself
+job
+join
+JPEG
+jungle
+just
+Karaoke
+keep
+keeping
+key
+kind
+king
+known
+label
+labels
+landscape
+language
+large
+last
+later
+latest
+lawn
+layout
+lead
+leader
+leaders
+lean
+leaves
+leaving
+left
+lemma
+length
+less
+let
+level
+levels
+libraries
+library
+lies
+like
+likely
+limit
+limiting
+limits
+line
+linear
+lines
+linewidth
+link
+linked
+linking
+Linux
+list
+lists
+little
+lives
+load
+loading
+loads
+located
+location
+locations
+logo
+long
+longer
+look
+looked
+looking
+looks
+lookup
+lookups
+loop
+lout
+low
+macro
+made
+magazine
+magic
+main
+major
+make
+makes
+making
+manage
+managed
+managing
+mandatory
+manipulate
+manipulation
+manner
+many
+map
+maps
+March
+margin
+mask
+masking
+Massachusetts
+match
+mathematical
+maximum
+may
+means
+meet
+member
+members
+memory
+merged
+method
+might
+milliseconds
+minimize
+minimum
+minor
+mix
+MNG
+mode
+model
+models
+modes
+modified
+module
+moments
+monitored
+monthly
+more
+most
+mostly
+move
+much
+multitude
+Munich
+must
+name
+named
+names
+necessary
+need
+needed
+needs
+network
+new
+news
+newsletter
+next
+nicely
+no
+none
+normally
+Norway
+not
+note
+notes
+nothing
+notifies
+notify
+now
+null
+number
+numbered
+numbering
+numbers
+Nydalen
+object
+objects
+obtain
+obtaining
+odd
+of
+off
+office
+offset
+offsets
+often
+old
+on
+once
+one
+ones
+online
+only
+onto
+opacity
+opaque
+open
+opens
+operates
+operating
+operation
+operations
+operator
+opportunity
+opposed
+optimize
+option
+optionally
+options
+or
+OR
+order
+ordinary
+original
+originally
+Oslo
+other
+otherwise
+our
+out
+outer
+outgoing
+output
+outside
+over
+overcoming
+overrides
+overview
+own
+owner
+owners
+pace
+Pacific
+package
+packages
+packets
+page
+pages
+paint
+painted
+painting
+paragraph
+paragraphs
+parameters
+parent
+Paris
+parse
+part
+partial
+partially
+particular
+partners
+parts
+party
+passed
+passing
+patches
+path
+pattern
+patterns
+pause
+PDF
+peek
+pending
+perform
+performed
+performs
+permission
+permutations
+personal
+pick
+pie
+pipe
+pixel
+pixels
+place
+places
+planning
+platforms
+play
+players
+playing
+please
+pleasing
+plugin
+plugins
+plus
+PNG
+pointer
+pop
+popular
+populates
+porter
+Porter
+portrait
+possibility
+possible
+potential
+potentially
+power
+powers
+preceded
+presence
+present
+prevent
+prevents
+previous
+previously
+primarily
+primary
+primitives
+printed
+printing
+prior
+probably
+problem
+process
+processes
+processing
+produce
+produced
+produces
+products
+programming
+programs
+project
+projects
+proof
+proper
+properly
+properties
+property
+proposed
+proposition
+pros
+protocols
+proud
+provide
+provided
+provides
+provision
+proxy
+public
+published
+punch
+punches
+pursuing
+put
+Qt
+Qtopia
+quality
+quarter
+quarterly
+queried
+queries
+query
+question
+questions
+radial
+ragged
+range
+rate
+rates
+rather
+ratio
+raw
+read
+reader
+reading
+reads
+ready
+real
+realistic
+really
+received
+recent
+recognized
+recommended
+recompile
+rectangle
+rectangular
+red
+redistribute
+reducing
+reference
+references
+reflect
+regardless
+regional
+register
+registered
+registration
+reimplement
+reimplementation
+reimplemented
+release
+released
+releases
+reliable
+rely
+remains
+remember
+removed
+removes
+repeatedly
+replace
+report
+represent
+represented
+represents
+reproduced
+requested
+require
+required
+requires
+resetting
+resides
+resolve
+respective
+respectively
+response
+rest
+restart
+result
+resulting
+resume
+return
+returning
+returns
+reuse
+revealing
+rich
+riches
+right
+roadshow
+role
+Roman
+router
+routers
+rule
+run
+runner
+runners
+running
+runs
+sake
+sales
+salespeople
+same
+sample
+San Jose
+save
+saved
+saves
+say
+scalable
+scale
+scanline
+scene
+scenes
+schedule
+school
+script
+seam
+seamless
+search
+searches
+searching
+second
+seconds
+section
+sections
+security
+see
+seen
+selection
+seminar
+seminars
+sending
+separated
+separates
+series
+service
+services
+set
+setting
+setup
+seven
+seventh
+several
+shade
+shadow
+shape
+shares
+shaves
+shine
+shorter
+should
+show
+shown
+shows
+side
+signal
+signals
+signature
+significantly
+similar
+similarily
+similarly
+simple
+simplest
+simplified
+simplifying
+simply
+simulate
+simultaneous
+since
+single
+size
+sizes
+slightly
+slope
+slot
+slowing
+small
+smaller
+so
+socket
+sockets
+software
+solutions
+solved
+some
+soon
+sort
+sorting
+source
+sources
+south
+space
+special
+specialized
+specific
+specifically
+specification
+specifications
+specified
+specify
+speed
+spend
+split
+SQL
+standard
+standards
+start
+starts
+starve
+state
+states
+static
+steady
+stealing
+step
+still
+stop
+stopwatch
+store
+stored
+stores
+straightforward
+stream
+string
+strings
+structure
+structured
+strut
+style
+styles
+styling
+subclass
+subclassing
+subdirectory
+subsection
+subsections
+succeeds
+success
+successful
+successfully
+such
+suggestion
+suggestions
+suitable
+support
+supported
+supports
+suppose
+supposes
+sure
+switch
+switches
+symbol
+symbols
+synonyms
+system
+systems
+table
+tables
+tags
+take
+takes
+tap
+target
+targets
+TCP
+team
+technique
+technology
+template
+templates
+Texas
+text
+than
+that
+the
+their
+them
+then
+theorem
+there
+these
+they
+thickness
+thin
+third
+this
+those
+three
+throttling
+through
+tightly
+time
+timer
+times
+tiny
+tips
+title
+titles
+to
+together
+too
+top
+torrent
+total
+tour
+trademarks
+traffic
+training
+transaction
+transfer
+transferred
+transferring
+transfers
+translucency
+translucent
+transparency
+transparent
+travel
+traveled
+true
+try
+turn
+twice
+two
+type
+typed
+typical
+typically
+unable
+under
+underlying
+understanding
+undoes
+unique
+united
+unlike
+unpack
+unsigned
+until
+untouched
+up
+update
+updated
+updates
+upload
+uploading
+uploads
+us
+use
+used
+useful
+user
+users
+uses
+using
+usual
+usually
+valid
+value
+values
+variable
+variation
+variety
+various
+vector
+venturing
+verifying
+versa
+version
+versions
+vertical
+very
+via
+vice
+virtual
+visual
+void
+VP
+waiting
+Wales
+want
+wants
+was
+way
+ways
+we
+web
+website
+well
+were
+what
+when
+whenever
+where
+whether
+which
+while
+whistle
+white
+who
+whole
+why
+widget
+widgets
+width
+widths
+will
+window
+windows
+wish
+with
+without
+word
+words
+work
+working
+works
+would
+wrap
+wrapper
+write
+writes
+writing
+writings
+written
+X
+X11
+XOR
+year
+years
+yes
+you
+your
+zero
diff --git a/examples/tools/customcompleter/textedit.cpp b/examples/tools/customcompleter/textedit.cpp
new file mode 100644
index 0000000000..4f6ae07e58
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textedit.h"
+#include <QCompleter>
+#include <QKeyEvent>
+#include <QAbstractItemView>
+#include <QtDebug>
+#include <QApplication>
+#include <QModelIndex>
+#include <QAbstractItemModel>
+#include <QScrollBar>
+
+//! [0]
+TextEdit::TextEdit(QWidget *parent)
+: QTextEdit(parent), c(0)
+{
+ setPlainText(tr("This TextEdit provides autocompletions for words that have more than"
+ " 3 characters. You can trigger autocompletion using ") +
+ QKeySequence("Ctrl+E").toString(QKeySequence::NativeText));
+}
+//! [0]
+
+//! [1]
+TextEdit::~TextEdit()
+{
+}
+//! [1]
+
+//! [2]
+void TextEdit::setCompleter(QCompleter *completer)
+{
+ if (c)
+ QObject::disconnect(c, 0, this, 0);
+
+ c = completer;
+
+ if (!c)
+ return;
+
+ c->setWidget(this);
+ c->setCompletionMode(QCompleter::PopupCompletion);
+ c->setCaseSensitivity(Qt::CaseInsensitive);
+ QObject::connect(c, SIGNAL(activated(QString)),
+ this, SLOT(insertCompletion(QString)));
+}
+//! [2]
+
+//! [3]
+QCompleter *TextEdit::completer() const
+{
+ return c;
+}
+//! [3]
+
+//! [4]
+void TextEdit::insertCompletion(const QString& completion)
+{
+ if (c->widget() != this)
+ return;
+ QTextCursor tc = textCursor();
+ int extra = completion.length() - c->completionPrefix().length();
+ tc.movePosition(QTextCursor::Left);
+ tc.movePosition(QTextCursor::EndOfWord);
+ tc.insertText(completion.right(extra));
+ setTextCursor(tc);
+}
+//! [4]
+
+//! [5]
+QString TextEdit::textUnderCursor() const
+{
+ QTextCursor tc = textCursor();
+ tc.select(QTextCursor::WordUnderCursor);
+ return tc.selectedText();
+}
+//! [5]
+
+//! [6]
+void TextEdit::focusInEvent(QFocusEvent *e)
+{
+ if (c)
+ c->setWidget(this);
+ QTextEdit::focusInEvent(e);
+}
+//! [6]
+
+//! [7]
+void TextEdit::keyPressEvent(QKeyEvent *e)
+{
+ if (c && c->popup()->isVisible()) {
+ // The following keys are forwarded by the completer to the widget
+ switch (e->key()) {
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ case Qt::Key_Escape:
+ case Qt::Key_Tab:
+ case Qt::Key_Backtab:
+ e->ignore();
+ return; // let the completer do default behavior
+ default:
+ break;
+ }
+ }
+
+ bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
+ if (!c || !isShortcut) // do not process the shortcut when we have a completer
+ QTextEdit::keyPressEvent(e);
+//! [7]
+
+//! [8]
+ const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
+ if (!c || (ctrlOrShift && e->text().isEmpty()))
+ return;
+
+ static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
+ bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
+ QString completionPrefix = textUnderCursor();
+
+ if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
+ || eow.contains(e->text().right(1)))) {
+ c->popup()->hide();
+ return;
+ }
+
+ if (completionPrefix != c->completionPrefix()) {
+ c->setCompletionPrefix(completionPrefix);
+ c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
+ }
+ QRect cr = cursorRect();
+ cr.setWidth(c->popup()->sizeHintForColumn(0)
+ + c->popup()->verticalScrollBar()->sizeHint().width());
+ c->complete(cr); // popup it up!
+}
+//! [8]
+
diff --git a/examples/tools/customcompleter/textedit.h b/examples/tools/customcompleter/textedit.h
new file mode 100644
index 0000000000..7ab21b740d
--- /dev/null
+++ b/examples/tools/customcompleter/textedit.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#include <QTextEdit>
+
+QT_BEGIN_NAMESPACE
+class QCompleter;
+QT_END_NAMESPACE
+
+//! [0]
+class TextEdit : public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ TextEdit(QWidget *parent = 0);
+ ~TextEdit();
+
+ void setCompleter(QCompleter *c);
+ QCompleter *completer() const;
+
+protected:
+ void keyPressEvent(QKeyEvent *e);
+ void focusInEvent(QFocusEvent *e);
+
+private slots:
+ void insertCompletion(const QString &completion);
+
+private:
+ QString textUnderCursor() const;
+
+private:
+ QCompleter *c;
+};
+//! [0]
+
+#endif // TEXTEDIT_H
+
diff --git a/examples/tools/customtype/customtype.pro b/examples/tools/customtype/customtype.pro
new file mode 100644
index 0000000000..3079964946
--- /dev/null
+++ b/examples/tools/customtype/customtype.pro
@@ -0,0 +1,3 @@
+HEADERS = message.h
+SOURCES = main.cpp \
+ message.cpp
diff --git a/examples/tools/customtype/main.cpp b/examples/tools/customtype/main.cpp
new file mode 100644
index 0000000000..6bb5889d25
--- /dev/null
+++ b/examples/tools/customtype/main.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QVariant>
+#include "message.h"
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: qt-info@nokia.com";
+ QString body = "This is a test.\r\n";
+
+//! [printing a custom type]
+ Message message(body, headers);
+ qDebug() << "Original:" << message;
+//! [printing a custom type]
+
+//! [storing a custom value]
+ QVariant stored;
+ stored.setValue(message);
+//! [storing a custom value]
+
+ qDebug() << "Stored:" << stored;
+
+//! [retrieving a custom value]
+ Message retrieved = stored.value<Message>();
+ qDebug() << "Retrieved:" << retrieved;
+ retrieved = qvariant_cast<Message>(stored);
+ qDebug() << "Retrieved:" << retrieved;
+//! [retrieving a custom value]
+
+ return 0;
+}
diff --git a/examples/tools/customtype/message.cpp b/examples/tools/customtype/message.cpp
new file mode 100644
index 0000000000..9eb67165cb
--- /dev/null
+++ b/examples/tools/customtype/message.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "message.h"
+
+//! [Message class implementation]
+Message::Message()
+{
+}
+
+Message::Message(const Message &other)
+{
+ m_body = other.m_body;
+ m_headers = other.m_headers;
+}
+
+Message::~Message()
+{
+}
+//! [Message class implementation]
+
+Message::Message(const QString &body, const QStringList &headers)
+{
+ m_body = body;
+ m_headers = headers;
+}
+
+//! [custom type streaming operator]
+QDebug operator<<(QDebug dbg, const Message &message)
+{
+ QStringList pieces = message.body().split("\r\n", QString::SkipEmptyParts);
+ if (pieces.isEmpty())
+ dbg.nospace() << "Message()";
+ else if (pieces.size() == 1)
+ dbg.nospace() << "Message(" << pieces.first() << ")";
+ else
+ dbg.nospace() << "Message(" << pieces.first() << " ...)";
+ return dbg.maybeSpace();
+}
+//! [custom type streaming operator]
+
+//! [getter functions]
+QString Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
+//! [getter functions]
diff --git a/examples/tools/customtype/message.h b/examples/tools/customtype/message.h
new file mode 100644
index 0000000000..1dcb46e23e
--- /dev/null
+++ b/examples/tools/customtype/message.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MESSAGE_H
+#define MESSAGE_H
+
+#include <QDebug>
+#include <QMetaType>
+#include <QStringList>
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message();
+ Message(const Message &other);
+ ~Message();
+
+ Message(const QString &body, const QStringList &headers);
+
+ QString body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+//! [custom type streaming operator]
+QDebug operator<<(QDebug dbg, const Message &message);
+//! [custom type streaming operator]
+
+#endif
diff --git a/examples/tools/customtypesending/customtypesending.pro b/examples/tools/customtypesending/customtypesending.pro
new file mode 100644
index 0000000000..b8b2aaf5fe
--- /dev/null
+++ b/examples/tools/customtypesending/customtypesending.pro
@@ -0,0 +1,5 @@
+HEADERS = message.h \
+ window.h
+SOURCES = main.cpp \
+ message.cpp \
+ window.cpp
diff --git a/examples/tools/customtypesending/main.cpp b/examples/tools/customtypesending/main.cpp
new file mode 100644
index 0000000000..436f467a4b
--- /dev/null
+++ b/examples/tools/customtypesending/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "message.h"
+#include "window.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ Window window1;
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: qt-info@nokia.com";
+ QString body = "This is a test.\r\n";
+ Message message(body, headers);
+ window1.setMessage(message);
+
+ Window window2;
+ QObject::connect(&window1, SIGNAL(messageSent(Message)),
+ &window2, SLOT(setMessage(Message)));
+ QObject::connect(&window2, SIGNAL(messageSent(Message)),
+ &window1, SLOT(setMessage(Message)));
+ window1.show();
+ window2.show();
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tools/customtypesending/message.cpp b/examples/tools/customtypesending/message.cpp
new file mode 100644
index 0000000000..0a23ff1938
--- /dev/null
+++ b/examples/tools/customtypesending/message.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "message.h"
+
+Message::Message()
+{
+}
+
+Message::Message(const Message &other)
+{
+ m_body = other.m_body;
+ m_headers = other.m_headers;
+}
+
+Message::~Message()
+{
+}
+
+Message::Message(const QString &body, const QStringList &headers)
+{
+ m_body = body;
+ m_headers = headers;
+}
+
+QString Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
diff --git a/examples/tools/customtypesending/message.h b/examples/tools/customtypesending/message.h
new file mode 100644
index 0000000000..429022bad3
--- /dev/null
+++ b/examples/tools/customtypesending/message.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MESSAGE_H
+#define MESSAGE_H
+
+#include <QDebug>
+#include <QMetaType>
+#include <QStringList>
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message();
+ Message(const Message &other);
+ ~Message();
+
+ Message(const QString &body, const QStringList &headers);
+
+ QString body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+#endif
diff --git a/examples/tools/customtypesending/window.cpp b/examples/tools/customtypesending/window.cpp
new file mode 100644
index 0000000000..24845a4279
--- /dev/null
+++ b/examples/tools/customtypesending/window.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "window.h"
+
+//! [Window constructor]
+Window::Window()
+{
+ editor = new QTextEdit();
+ QPushButton *sendButton = new QPushButton(tr("&Send message"));
+
+ connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout();
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(sendButton);
+ buttonLayout->addStretch();
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(editor);
+ layout->addLayout(buttonLayout);
+
+ setWindowTitle(tr("Custom Type Sending"));
+}
+//! [Window constructor]
+
+//! [sending a message]
+void Window::sendMessage()
+{
+ thisMessage = Message(editor->toPlainText(), thisMessage.headers());
+ emit messageSent(thisMessage);
+}
+//! [sending a message]
+
+//! [receiving a message]
+void Window::setMessage(const Message &message)
+{
+ thisMessage = message;
+ editor->setPlainText(thisMessage.body());
+}
+//! [receiving a message]
diff --git a/examples/tools/customtypesending/window.h b/examples/tools/customtypesending/window.h
new file mode 100644
index 0000000000..a4e7ec2302
--- /dev/null
+++ b/examples/tools/customtypesending/window.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include "message.h"
+
+class QTextEdit;
+
+//! [Window class definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+signals:
+ void messageSent(const Message &message);
+
+public slots:
+ void setMessage(const Message &message);
+
+private slots:
+ void sendMessage();
+
+private:
+ Message thisMessage;
+ QTextEdit *editor;
+};
+//! [Window class definition]
+
+#endif
diff --git a/examples/tools/echoplugin/echoplugin.pro b/examples/tools/echoplugin/echoplugin.pro
new file mode 100644
index 0000000000..80520b274d
--- /dev/null
+++ b/examples/tools/echoplugin/echoplugin.pro
@@ -0,0 +1,13 @@
+#! [0]
+TEMPLATE = subdirs
+SUBDIRS = echowindow \
+ plugin
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echoplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/echoplugin/echowindow/echointerface.h b/examples/tools/echoplugin/echowindow/echointerface.h
new file mode 100644
index 0000000000..885dd63848
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echointerface.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ECHOINTERFACE_H
+#define ECHOINTERFACE_H
+
+#include <QString>
+
+//! [0]
+class EchoInterface
+{
+public:
+ virtual ~EchoInterface() {}
+ virtual QString echo(const QString &message) = 0;
+};
+
+
+QT_BEGIN_NAMESPACE
+Q_DECLARE_INTERFACE(EchoInterface,
+ "com.trolltech.Plugin.EchoInterface/1.0");
+QT_END_NAMESPACE
+
+//! [0]
+#endif
diff --git a/examples/tools/echoplugin/echowindow/echowindow.cpp b/examples/tools/echoplugin/echowindow/echowindow.cpp
new file mode 100644
index 0000000000..9e6460a3f7
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echowindow.h"
+
+//! [0]
+EchoWindow::EchoWindow()
+{
+ createGUI();
+ setLayout(layout);
+ setWindowTitle("Echo Plugin Example");
+
+ if (!loadPlugin()) {
+ QMessageBox::information(this, "Error", "Could not load the plugin");
+ lineEdit->setEnabled(false);
+ button->setEnabled(false);
+ }
+}
+//! [0]
+
+//! [1]
+void EchoWindow::sendEcho()
+{
+ QString text = echoInterface->echo(lineEdit->text());
+ label->setText(text);
+}
+//! [1]
+
+//! [2]
+void EchoWindow::createGUI()
+{
+ lineEdit = new QLineEdit;
+ label = new QLabel;
+ label->setFrameStyle(QFrame::Box | QFrame::Plain);
+ button = new QPushButton(tr("Send Message"));
+
+ connect(lineEdit, SIGNAL(editingFinished()),
+ this, SLOT(sendEcho()));
+ connect(button, SIGNAL(clicked()),
+ this, SLOT(sendEcho()));
+
+ layout = new QGridLayout;
+ layout->addWidget(new QLabel(tr("Message:")), 0, 0);
+ layout->addWidget(lineEdit, 0, 1);
+ layout->addWidget(new QLabel(tr("Answer:")), 1, 0);
+ layout->addWidget(label, 1, 1);
+ layout->addWidget(button, 2, 1, Qt::AlignRight);
+ layout->setSizeConstraint(QLayout::SetFixedSize);
+}
+//! [2]
+
+//! [3]
+bool EchoWindow::loadPlugin()
+{
+ QDir pluginsDir(qApp->applicationDirPath());
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == "MacOS") {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+ pluginsDir.cd("plugins");
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = pluginLoader.instance();
+ if (plugin) {
+ echoInterface = qobject_cast<EchoInterface *>(plugin);
+ if (echoInterface)
+ return true;
+ }
+ }
+
+ return false;
+}
+//! [3]
diff --git a/examples/tools/echoplugin/echowindow/echowindow.h b/examples/tools/echoplugin/echowindow/echowindow.h
new file mode 100644
index 0000000000..dc1ebdb685
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ECHODIALOG_H
+#define ECHODIALOG_H
+
+#include <QWidget>
+
+#include "echointerface.h"
+
+QT_BEGIN_NAMESPACE
+class QString;
+class QLineEdit;
+class QLabel;
+class QPushButton;
+class QGridLayout;
+QT_END_NAMESPACE
+
+//! [0]
+class EchoWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ EchoWindow();
+
+private slots:
+ void sendEcho();
+
+private:
+ void createGUI();
+ bool loadPlugin();
+
+ EchoInterface *echoInterface;
+ QLineEdit *lineEdit;
+ QLabel *label;
+ QPushButton *button;
+ QGridLayout *layout;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/echoplugin/echowindow/echowindow.pro b/examples/tools/echoplugin/echowindow/echowindow.pro
new file mode 100644
index 0000000000..7bd772ae80
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/echowindow.pro
@@ -0,0 +1,21 @@
+HEADERS = echowindow.h \
+ echointerface.h
+SOURCES = echowindow.cpp \
+ main.cpp
+
+TARGET = echoplugin
+QMAKE_PROJECT_NAME = echopluginwindow
+win32 {
+ CONFIG(debug, release|debug):DESTDIR = ../debug/
+ CONFIG(release, release|debug):DESTDIR = ../release/
+} else {
+ DESTDIR = ../
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS echowindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin/echowindow
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/echoplugin/echowindow/main.cpp b/examples/tools/echoplugin/echowindow/main.cpp
new file mode 100644
index 0000000000..585c8da6e7
--- /dev/null
+++ b/examples/tools/echoplugin/echowindow/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echowindow.h"
+#include "echointerface.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ QApplication app(argv, args);
+
+ EchoWindow window;
+ window.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/echoplugin/plugin/echoplugin.cpp b/examples/tools/echoplugin/plugin/echoplugin.cpp
new file mode 100644
index 0000000000..099ab81cb1
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "echoplugin.h"
+
+//! [0]
+QString EchoPlugin::echo(const QString &message)
+{
+ return message;
+}
+//! [0]
+
+//! [1]
+Q_EXPORT_PLUGIN2(echoplugin, EchoPlugin);
+//! [1]
diff --git a/examples/tools/echoplugin/plugin/echoplugin.h b/examples/tools/echoplugin/plugin/echoplugin.h
new file mode 100644
index 0000000000..dca889c5f2
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/echoplugin.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ECHOPLUGIN_H
+#define ECHOPLUGIN_H
+
+#include <QObject>
+#include "echoplugin.h"
+#include "echointerface.h"
+
+//! [0]
+class EchoPlugin : public QObject, EchoInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(EchoInterface)
+
+public:
+ QString echo(const QString &message);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/echoplugin/plugin/plugin.pro b/examples/tools/echoplugin/plugin/plugin.pro
new file mode 100644
index 0000000000..1354e95ff7
--- /dev/null
+++ b/examples/tools/echoplugin/plugin/plugin.pro
@@ -0,0 +1,19 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../echowindow
+HEADERS = echoplugin.h
+SOURCES = echoplugin.cpp
+TARGET = $$qtLibraryTarget(echoplugin)
+DESTDIR = ../plugins
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin/plugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/echoplugin/plugin
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/i18n/i18n.pro b/examples/tools/i18n/i18n.pro
new file mode 100644
index 0000000000..fded91971c
--- /dev/null
+++ b/examples/tools/i18n/i18n.pro
@@ -0,0 +1,28 @@
+HEADERS = languagechooser.h \
+ mainwindow.h
+SOURCES = languagechooser.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES += i18n.qrc
+TRANSLATIONS += translations/i18n_ar.ts \
+ translations/i18n_cs.ts \
+ translations/i18n_de.ts \
+ translations/i18n_el.ts \
+ translations/i18n_en.ts \
+ translations/i18n_eo.ts \
+ translations/i18n_fr.ts \
+ translations/i18n_it.ts \
+ translations/i18n_jp.ts \
+ translations/i18n_ko.ts \
+ translations/i18n_no.ts \
+ translations/i18n_ru.ts \
+ translations/i18n_sv.ts \
+ translations/i18n_zh.ts
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/i18n
+sources.files = $$SOURCES $$HEADERS $$RESOURCES translations i18n.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/i18n
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/i18n/i18n.qrc b/examples/tools/i18n/i18n.qrc
new file mode 100644
index 0000000000..16a89f140b
--- /dev/null
+++ b/examples/tools/i18n/i18n.qrc
@@ -0,0 +1,18 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>translations/i18n_ar.qm</file>
+ <file>translations/i18n_cs.qm</file>
+ <file>translations/i18n_de.qm</file>
+ <file>translations/i18n_el.qm</file>
+ <file>translations/i18n_en.qm</file>
+ <file>translations/i18n_eo.qm</file>
+ <file>translations/i18n_fr.qm</file>
+ <file>translations/i18n_it.qm</file>
+ <file>translations/i18n_jp.qm</file>
+ <file>translations/i18n_ko.qm</file>
+ <file>translations/i18n_no.qm</file>
+ <file>translations/i18n_ru.qm</file>
+ <file>translations/i18n_sv.qm</file>
+ <file>translations/i18n_zh.qm</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/i18n/languagechooser.cpp b/examples/tools/i18n/languagechooser.cpp
new file mode 100644
index 0000000000..888e6aca83
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "languagechooser.h"
+#include "mainwindow.h"
+
+#ifdef Q_WS_MAC
+QT_BEGIN_NAMESPACE
+extern void qt_mac_set_menubar_merge(bool merge);
+QT_END_NAMESPACE
+#endif
+
+LanguageChooser::LanguageChooser(QWidget *parent)
+ : QDialog(parent, Qt::WindowStaysOnTopHint)
+{
+ groupBox = new QGroupBox("Languages");
+
+ QGridLayout *groupBoxLayout = new QGridLayout;
+
+ QStringList qmFiles = findQmFiles();
+ for (int i = 0; i < qmFiles.size(); ++i) {
+ QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i]));
+ qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]);
+ connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(checkBoxToggled()));
+ groupBoxLayout->addWidget(checkBox, i / 2, i % 2);
+ }
+ groupBox->setLayout(groupBoxLayout);
+
+ buttonBox = new QDialogButtonBox;
+
+ showAllButton = buttonBox->addButton("Show All",
+ QDialogButtonBox::ActionRole);
+ hideAllButton = buttonBox->addButton("Hide All",
+ QDialogButtonBox::ActionRole);
+
+ connect(showAllButton, SIGNAL(clicked()), this, SLOT(showAll()));
+ connect(hideAllButton, SIGNAL(clicked()), this, SLOT(hideAll()));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(groupBox);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
+
+#ifdef Q_WS_MAC
+ qt_mac_set_menubar_merge(false);
+#endif
+
+ setWindowTitle("I18N");
+}
+
+bool LanguageChooser::eventFilter(QObject *object, QEvent *event)
+{
+ if (event->type() == QEvent::Close) {
+ MainWindow *window = qobject_cast<MainWindow *>(object);
+ if (window) {
+ QCheckBox *checkBox = mainWindowForCheckBoxMap.key(window);
+ if (checkBox)
+ checkBox->setChecked(false);
+ }
+ }
+ return QWidget::eventFilter(object, event);
+}
+
+void LanguageChooser::closeEvent(QCloseEvent * /* event */)
+{
+ qApp->quit();
+}
+
+void LanguageChooser::checkBoxToggled()
+{
+ QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
+ MainWindow *window = mainWindowForCheckBoxMap[checkBox];
+ if (!window) {
+ QTranslator translator;
+ translator.load(qmFileForCheckBoxMap[checkBox]);
+ qApp->installTranslator(&translator);
+
+ window = new MainWindow;
+ window->setPalette(colorForLanguage(checkBox->text()));
+
+ window->installEventFilter(this);
+ mainWindowForCheckBoxMap.insert(checkBox, window);
+ }
+ window->setVisible(checkBox->isChecked());
+}
+
+void LanguageChooser::showAll()
+{
+ foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
+ checkBox->setChecked(true);
+}
+
+void LanguageChooser::hideAll()
+{
+ foreach (QCheckBox *checkBox, qmFileForCheckBoxMap.keys())
+ checkBox->setChecked(false);
+}
+
+QStringList LanguageChooser::findQmFiles()
+{
+ QDir dir(":/translations");
+ QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files,
+ QDir::Name);
+ QMutableStringListIterator i(fileNames);
+ while (i.hasNext()) {
+ i.next();
+ i.setValue(dir.filePath(i.value()));
+ }
+ return fileNames;
+}
+
+QString LanguageChooser::languageName(const QString &qmFile)
+{
+ QTranslator translator;
+ translator.load(qmFile);
+
+ return translator.translate("MainWindow", "English");
+}
+
+QColor LanguageChooser::colorForLanguage(const QString &language)
+{
+ uint hashValue = qHash(language);
+ int red = 156 + (hashValue & 0x3F);
+ int green = 156 + ((hashValue >> 6) & 0x3F);
+ int blue = 156 + ((hashValue >> 12) & 0x3F);
+ return QColor(red, green, blue);
+}
diff --git a/examples/tools/i18n/languagechooser.h b/examples/tools/i18n/languagechooser.h
new file mode 100644
index 0000000000..15378df7f3
--- /dev/null
+++ b/examples/tools/i18n/languagechooser.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LANGUAGECHOOSER_H
+#define LANGUAGECHOOSER_H
+
+#include <QDialog>
+#include <QMap>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QAbstractButton;
+class QCheckBox;
+class QDialogButtonBox;
+class QGroupBox;
+QT_END_NAMESPACE
+class MainWindow;
+
+class LanguageChooser : public QDialog
+{
+ Q_OBJECT
+
+public:
+ LanguageChooser(QWidget *parent = 0);
+
+protected:
+ bool eventFilter(QObject *object, QEvent *event);
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void checkBoxToggled();
+ void showAll();
+ void hideAll();
+
+private:
+ QStringList findQmFiles();
+ QString languageName(const QString &qmFile);
+ QColor colorForLanguage(const QString &language);
+
+ QGroupBox *groupBox;
+ QDialogButtonBox *buttonBox;
+ QAbstractButton *showAllButton;
+ QAbstractButton *hideAllButton;
+ QMap<QCheckBox *, QString> qmFileForCheckBoxMap;
+ QMap<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
+};
+
+#endif
diff --git a/examples/tools/i18n/main.cpp b/examples/tools/i18n/main.cpp
new file mode 100644
index 0000000000..ebc7a2bb27
--- /dev/null
+++ b/examples/tools/i18n/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "languagechooser.h"
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(i18n);
+
+ QApplication app(argc, argv);
+ LanguageChooser chooser;
+ chooser.show();
+ return app.exec();
+}
diff --git a/examples/tools/i18n/mainwindow.cpp b/examples/tools/i18n/mainwindow.cpp
new file mode 100644
index 0000000000..8e1b14160f
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+static const char * const listEntries[] = {
+ QT_TRANSLATE_NOOP("MainWindow", "First"),
+ QT_TRANSLATE_NOOP("MainWindow", "Second"),
+ QT_TRANSLATE_NOOP("MainWindow", "Third"),
+ 0
+};
+
+MainWindow::MainWindow()
+{
+ centralWidget = new QWidget;
+ setCentralWidget(centralWidget);
+
+ createGroupBox();
+
+ listWidget = new QListWidget;
+ for (int i = 0; listEntries[i]; ++i)
+ listWidget->addItem(tr(listEntries[i]));
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(groupBox);
+ mainLayout->addWidget(listWidget);
+ centralWidget->setLayout(mainLayout);
+
+ exitAction = new QAction(tr("E&xit"), this);
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->setPalette(QPalette(Qt::red));
+ fileMenu->addAction(exitAction);
+
+ setWindowTitle(tr("Language: %1").arg(tr("English")));
+ statusBar()->showMessage(tr("Internationalization Example"));
+
+ if (tr("LTR") == "RTL")
+ setLayoutDirection(Qt::RightToLeft);
+}
+
+void MainWindow::createGroupBox()
+{
+ groupBox = new QGroupBox(tr("View"));
+ perspectiveRadioButton = new QRadioButton(tr("Perspective"));
+ isometricRadioButton = new QRadioButton(tr("Isometric"));
+ obliqueRadioButton = new QRadioButton(tr("Oblique"));
+ perspectiveRadioButton->setChecked(true);
+
+ QVBoxLayout *groupBoxLayout = new QVBoxLayout;
+ groupBoxLayout->addWidget(perspectiveRadioButton);
+ groupBoxLayout->addWidget(isometricRadioButton);
+ groupBoxLayout->addWidget(obliqueRadioButton);
+ groupBox->setLayout(groupBoxLayout);
+}
diff --git a/examples/tools/i18n/mainwindow.h b/examples/tools/i18n/mainwindow.h
new file mode 100644
index 0000000000..dff0767742
--- /dev/null
+++ b/examples/tools/i18n/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QGroupBox;
+class QLabel;
+class QListWidget;
+class QMenu;
+class QRadioButton;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private:
+ void createGroupBox();
+
+ QWidget *centralWidget;
+ QLabel *label;
+ QGroupBox *groupBox;
+ QListWidget *listWidget;
+ QRadioButton *perspectiveRadioButton;
+ QRadioButton *isometricRadioButton;
+ QRadioButton *obliqueRadioButton;
+ QMenu *fileMenu;
+ QAction *exitAction;
+};
+
+#endif
diff --git a/examples/tools/i18n/translations/i18n_ar.qm b/examples/tools/i18n/translations/i18n_ar.qm
new file mode 100644
index 0000000000..a134c468bb
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ar.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ar.ts b/examples/tools/i18n/translations/i18n_ar.ts
new file mode 100644
index 0000000000..a7ec2c9404
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ar.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>First</source>
+ <translation>أول</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>مثال التدويل</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>متماثل</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>اللغة: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>العربية</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>مصمت</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>منظور</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>ثانى</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>ثالث</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>مرئى</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>أخرج</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>الملف</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>RTL</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_cs.qm b/examples/tools/i18n/translations/i18n_cs.qm
new file mode 100644
index 0000000000..5b7ff95b05
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_cs.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_cs.ts b/examples/tools/i18n/translations/i18n_cs.ts
new file mode 100644
index 0000000000..6c4dee9b2e
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_cs.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Pohled</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Soubor</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Konec</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>První</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Třetí</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Jayzk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Český</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Nakloněný</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Druhý</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrický</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivní</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Ukázka lokalizace</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_de.qm b/examples/tools/i18n/translations/i18n_de.qm
new file mode 100644
index 0000000000..177fc49b8b
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_de.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_de.ts b/examples/tools/i18n/translations/i18n_de.ts
new file mode 100644
index 0000000000..249a61d020
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_de.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Ansicht</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Datei</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Be&amp;enden</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Erstens</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Drittens</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Deutsch</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Sprache: %1</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Schief</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Zweitens</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrisch</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivisch</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationalisierungsbeispiel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_el.qm b/examples/tools/i18n/translations/i18n_el.qm
new file mode 100644
index 0000000000..5483291bb0
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_el.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_el.ts b/examples/tools/i18n/translations/i18n_el.ts
new file mode 100644
index 0000000000..d23a0aad3e
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_el.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Αρχείο</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Έ&amp;ξοδος</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Πρώτο</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Παράδειγμα διεθνοποίησης</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Ισομετρική</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Γλώσσα: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Ελληνικά</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Πλάγια</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Προοπτική</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Δεύτερο</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Τρίτο</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Όψη</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_en.qm b/examples/tools/i18n/translations/i18n_en.qm
new file mode 100644
index 0000000000..9190ac7e6f
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_en.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_en.ts b/examples/tools/i18n/translations/i18n_en.ts
new file mode 100644
index 0000000000..ca38e958c1
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_en.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>E&amp;xit</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;File</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationalization Example</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Language: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>English</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>View</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspective</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometric</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblique</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>First</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Second</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Third</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_eo.qm b/examples/tools/i18n/translations/i18n_eo.qm
new file mode 100644
index 0000000000..a8457bef06
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_eo.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_eo.ts b/examples/tools/i18n/translations/i18n_eo.ts
new file mode 100644
index 0000000000..16a37becd9
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_eo.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Dosiero</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Unue</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Ekzemplo pri internaciigo</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometria</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Lingvo: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Esperanto</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblikva</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektiva</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Due</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Trie</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Aspekto</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Fini</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_fr.qm b/examples/tools/i18n/translations/i18n_fr.qm
new file mode 100644
index 0000000000..3e8a69b80d
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_fr.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_fr.ts b/examples/tools/i18n/translations/i18n_fr.ts
new file mode 100644
index 0000000000..0012892ef2
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_fr.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Vue</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Fichier</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Quitter</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Premier</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Troisième</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Langue : %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Français</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Oblique</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Deuxième</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isométrique</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspective</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Exemple d&apos;internationalisation</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_it.qm b/examples/tools/i18n/translations/i18n_it.qm
new file mode 100644
index 0000000000..3dffd30548
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_it.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_it.ts b/examples/tools/i18n/translations/i18n_it.ts
new file mode 100644
index 0000000000..d516a277b6
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_it.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>First</source>
+ <translation>Primo</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Esempio di localizzazione</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrica</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Lingua: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Italiano</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Obliqua</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Prospettica</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Secondo</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Terzo</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>Vista</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Esci</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;File</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_jp.qm b/examples/tools/i18n/translations/i18n_jp.qm
new file mode 100644
index 0000000000..017bc96cfc
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_jp.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_jp.ts b/examples/tools/i18n/translations/i18n_jp.ts
new file mode 100644
index 0000000000..067b5a8a0b
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_jp.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>ファイル(&amp;F)</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>終了(&amp;X)</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>第一行</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>国際化(i18n)の例</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>等角投影法</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>言語: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>日本語</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>斜め投影法</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>遠近法</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>第二行</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>第三行</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>表示方式</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_ko.qm b/examples/tools/i18n/translations/i18n_ko.qm
new file mode 100644
index 0000000000..d61b93db39
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ko.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ko.ts b/examples/tools/i18n/translations/i18n_ko.ts
new file mode 100644
index 0000000000..bfd5924518
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ko.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>&amp;File</source>
+ <translation>파일&amp;F</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>종료&amp;X</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>첫번째</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>국제화 예제</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>등측도</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>언어 : %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>한국어</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>빗각</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>원근화법</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>두번째</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>세번째</translation>
+ </message>
+ <message>
+ <source>View</source>
+ <translation>보기</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_no.qm b/examples/tools/i18n/translations/i18n_no.qm
new file mode 100644
index 0000000000..c84b0d74ba
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_no.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_no.ts b/examples/tools/i18n/translations/i18n_no.ts
new file mode 100644
index 0000000000..2e06974997
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_no.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Vis</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Fil</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Avslutt</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Første</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Tredje</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Språk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Norsk</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Skjevt</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Andre</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometrisk</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektiv</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internasjonaliseringseksempel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_ru.qm b/examples/tools/i18n/translations/i18n_ru.qm
new file mode 100644
index 0000000000..a76e1b8703
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ru.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_ru.ts b/examples/tools/i18n/translations/i18n_ru.ts
new file mode 100644
index 0000000000..748cc12fd9
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_ru.ts
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1" language="ru">
+<defaultcodec></defaultcodec>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Вид</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>Файл</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>Выход</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Первый</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Третий</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Язык: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Русский</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Курсив</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Второй</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Изометрический</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Перспектива</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Пример интернационализации</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_sv.qm b/examples/tools/i18n/translations/i18n_sv.qm
new file mode 100644
index 0000000000..7204b308b1
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_sv.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_sv.ts b/examples/tools/i18n/translations/i18n_sv.ts
new file mode 100644
index 0000000000..ac4ab98bd3
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_sv.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>Visa</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>&amp;Arkiv</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>&amp;Avsluta</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>Första</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>Tredje</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>Språk: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>Svenska</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>Skevt</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>Andra</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>Isometriskt</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>Perspektivt</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>Internationaliseringsexempel</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/i18n/translations/i18n_zh.qm b/examples/tools/i18n/translations/i18n_zh.qm
new file mode 100644
index 0000000000..32053f4633
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_zh.qm
Binary files differ
diff --git a/examples/tools/i18n/translations/i18n_zh.ts b/examples/tools/i18n/translations/i18n_zh.ts
new file mode 100644
index 0000000000..3b715470a8
--- /dev/null
+++ b/examples/tools/i18n/translations/i18n_zh.ts
@@ -0,0 +1,57 @@
+<!DOCTYPE TS><TS>
+<context>
+ <name>MainWindow</name>
+ <message>
+ <source>View</source>
+ <translation>视图</translation>
+ </message>
+ <message>
+ <source>&amp;File</source>
+ <translation>文件[&amp;F]</translation>
+ </message>
+ <message>
+ <source>E&amp;xit</source>
+ <translation>退出[&amp;x]</translation>
+ </message>
+ <message>
+ <source>First</source>
+ <translation>第一个</translation>
+ </message>
+ <message>
+ <source>Third</source>
+ <translation>第三个</translation>
+ </message>
+ <message>
+ <source>Language: %1</source>
+ <translation>语言: %1</translation>
+ </message>
+ <message>
+ <source>English</source>
+ <translation>简体中文</translation>
+ </message>
+ <message>
+ <source>Oblique</source>
+ <translation>斜投影</translation>
+ </message>
+ <message>
+ <source>Second</source>
+ <translation>第二个</translation>
+ </message>
+ <message>
+ <source>Isometric</source>
+ <translation>等角投影</translation>
+ </message>
+ <message>
+ <source>Perspective</source>
+ <translation>透视投影</translation>
+ </message>
+ <message>
+ <source>Internationalization Example</source>
+ <translation>国际化范例</translation>
+ </message>
+ <message>
+ <source>LTR</source>
+ <translation>LTR</translation>
+ </message>
+</context>
+</TS>
diff --git a/examples/tools/inputpanel/inputpanel.pro b/examples/tools/inputpanel/inputpanel.pro
new file mode 100644
index 0000000000..a1e5f0f926
--- /dev/null
+++ b/examples/tools/inputpanel/inputpanel.pro
@@ -0,0 +1,17 @@
+SOURCES += main.cpp \
+ myinputpanel.cpp \
+ myinputpanelcontext.cpp
+
+HEADERS += myinputpanel.h \
+ myinputpanelcontext.h
+
+FORMS += mainform.ui \
+ myinputpanelform.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/inputpanel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS inputpanel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/inputpanel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/inputpanel/main.cpp b/examples/tools/inputpanel/main.cpp
new file mode 100644
index 0000000000..2760e98d79
--- /dev/null
+++ b/examples/tools/inputpanel/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QWidget>
+
+//! [main]
+#include "myinputpanelcontext.h"
+#include "ui_mainform.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MyInputPanelContext *ic = new MyInputPanelContext;
+ app.setInputContext(ic);
+
+ QWidget widget;
+ Ui::MainForm form;
+ form.setupUi(&widget);
+ widget.show();
+ return app.exec();
+}
+//! [main]
diff --git a/examples/tools/inputpanel/mainform.ui b/examples/tools/inputpanel/mainform.ui
new file mode 100644
index 0000000000..c16ae31510
--- /dev/null
+++ b/examples/tools/inputpanel/mainform.ui
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainForm</class>
+ <widget class="QWidget" name="MainForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>140</width>
+ <height>200</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Input Panel Example</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>My age:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+ </property>
+ <property name="buddy">
+ <cstring>lineEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>My phone number:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+ </property>
+ <property name="buddy">
+ <cstring>lineEdit_2</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit_2"/>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>My gender:</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="radioButton">
+ <property name="text">
+ <string>Male</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButton_2">
+ <property name="text">
+ <string>Female</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/tools/inputpanel/myinputpanel.cpp b/examples/tools/inputpanel/myinputpanel.cpp
new file mode 100644
index 0000000000..c58d27d790
--- /dev/null
+++ b/examples/tools/inputpanel/myinputpanel.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "myinputpanel.h"
+
+//! [0]
+
+MyInputPanel::MyInputPanel()
+ : QWidget(0, Qt::Tool | Qt::WindowStaysOnTopHint),
+ lastFocusedWidget(0)
+{
+ form.setupUi(this);
+
+ connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
+ this, SLOT(saveFocusWidget(QWidget*,QWidget*)));
+
+ signalMapper.setMapping(form.panelButton_1, form.panelButton_1);
+ signalMapper.setMapping(form.panelButton_2, form.panelButton_2);
+ signalMapper.setMapping(form.panelButton_3, form.panelButton_3);
+ signalMapper.setMapping(form.panelButton_4, form.panelButton_4);
+ signalMapper.setMapping(form.panelButton_5, form.panelButton_5);
+ signalMapper.setMapping(form.panelButton_6, form.panelButton_6);
+ signalMapper.setMapping(form.panelButton_7, form.panelButton_7);
+ signalMapper.setMapping(form.panelButton_8, form.panelButton_8);
+ signalMapper.setMapping(form.panelButton_9, form.panelButton_9);
+ signalMapper.setMapping(form.panelButton_star, form.panelButton_star);
+ signalMapper.setMapping(form.panelButton_0, form.panelButton_0);
+ signalMapper.setMapping(form.panelButton_hash, form.panelButton_hash);
+
+ connect(form.panelButton_1, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_2, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_3, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_4, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_5, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_6, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_7, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_8, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_9, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_star, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_0, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+ connect(form.panelButton_hash, SIGNAL(clicked()),
+ &signalMapper, SLOT(map()));
+
+ connect(&signalMapper, SIGNAL(mapped(QWidget*)),
+ this, SLOT(buttonClicked(QWidget*)));
+}
+
+//! [0]
+
+bool MyInputPanel::event(QEvent *e)
+{
+ switch (e->type()) {
+//! [1]
+ case QEvent::WindowActivate:
+ if (lastFocusedWidget)
+ lastFocusedWidget->activateWindow();
+ break;
+//! [1]
+ default:
+ break;
+ }
+
+ return QWidget::event(e);
+}
+
+//! [2]
+
+void MyInputPanel::saveFocusWidget(QWidget * /*oldFocus*/, QWidget *newFocus)
+{
+ if (newFocus != 0 && !this->isAncestorOf(newFocus)) {
+ lastFocusedWidget = newFocus;
+ }
+}
+
+//! [2]
+
+//! [3]
+
+void MyInputPanel::buttonClicked(QWidget *w)
+{
+ QChar chr = qvariant_cast<QChar>(w->property("buttonValue"));
+ emit characterGenerated(chr);
+}
+
+//! [3]
diff --git a/examples/tools/inputpanel/myinputpanel.h b/examples/tools/inputpanel/myinputpanel.h
new file mode 100644
index 0000000000..c1d5d1ff25
--- /dev/null
+++ b/examples/tools/inputpanel/myinputpanel.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYINPUTPANEL_H
+#define MYINPUTPANEL_H
+
+#include <QtGui>
+#include <QtCore>
+
+#include "ui_myinputpanelform.h"
+
+//! [0]
+
+class MyInputPanel : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MyInputPanel();
+
+signals:
+ void characterGenerated(QChar character);
+
+protected:
+ bool event(QEvent *e);
+
+private slots:
+ void saveFocusWidget(QWidget *oldFocus, QWidget *newFocus);
+ void buttonClicked(QWidget *w);
+
+private:
+ Ui::MyInputPanelForm form;
+ QWidget *lastFocusedWidget;
+ QSignalMapper signalMapper;
+};
+
+//! [0]
+
+#endif // MYINPUTPANEL_H
diff --git a/examples/tools/inputpanel/myinputpanelcontext.cpp b/examples/tools/inputpanel/myinputpanelcontext.cpp
new file mode 100644
index 0000000000..a09964ab9e
--- /dev/null
+++ b/examples/tools/inputpanel/myinputpanelcontext.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+
+#include "myinputpanelcontext.h"
+
+//! [0]
+
+MyInputPanelContext::MyInputPanelContext()
+{
+ inputPanel = new MyInputPanel;
+ connect(inputPanel, SIGNAL(characterGenerated(QChar)), SLOT(sendCharacter(QChar)));
+}
+
+//! [0]
+
+MyInputPanelContext::~MyInputPanelContext()
+{
+ delete inputPanel;
+}
+
+//! [1]
+
+bool MyInputPanelContext::filterEvent(const QEvent* event)
+{
+ if (event->type() == QEvent::RequestSoftwareInputPanel) {
+ updatePosition();
+ inputPanel->show();
+ return true;
+ } else if (event->type() == QEvent::CloseSoftwareInputPanel) {
+ inputPanel->hide();
+ return true;
+ }
+ return false;
+}
+
+//! [1]
+
+QString MyInputPanelContext::identifierName()
+{
+ return "MyInputPanelContext";
+}
+
+void MyInputPanelContext::reset()
+{
+}
+
+bool MyInputPanelContext::isComposing() const
+{
+ return false;
+}
+
+QString MyInputPanelContext::language()
+{
+ return "en_US";
+}
+
+//! [2]
+
+void MyInputPanelContext::sendCharacter(QChar character)
+{
+ QPointer<QWidget> w = focusWidget();
+
+ if (!w)
+ return;
+
+ QKeyEvent keyPress(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString(character));
+ QApplication::sendEvent(w, &keyPress);
+
+ if (!w)
+ return;
+
+ QKeyEvent keyRelease(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString());
+ QApplication::sendEvent(w, &keyRelease);
+}
+
+//! [2]
+
+//! [3]
+
+void MyInputPanelContext::updatePosition()
+{
+ QWidget *widget = focusWidget();
+ if (!widget)
+ return;
+
+ QRect widgetRect = widget->rect();
+ QPoint panelPos = QPoint(widgetRect.left(), widgetRect.bottom() + 2);
+ panelPos = widget->mapToGlobal(panelPos);
+ inputPanel->move(panelPos);
+}
+
+//! [3]
diff --git a/examples/tools/inputpanel/myinputpanelcontext.h b/examples/tools/inputpanel/myinputpanelcontext.h
new file mode 100644
index 0000000000..bb40e211a7
--- /dev/null
+++ b/examples/tools/inputpanel/myinputpanelcontext.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYINPUTPANELCONTEXT_H
+#define MYINPUTPANELCONTEXT_H
+
+#include <QtGui/QInputContext>
+
+#include "myinputpanel.h"
+
+class MyInputPanel;
+
+//! [0]
+
+class MyInputPanelContext : public QInputContext
+{
+ Q_OBJECT
+
+public:
+ MyInputPanelContext();
+ ~MyInputPanelContext();
+
+ bool filterEvent(const QEvent* event);
+
+ QString identifierName();
+ QString language();
+
+ bool isComposing() const;
+
+ void reset();
+
+private slots:
+ void sendCharacter(QChar character);
+
+private:
+ void updatePosition();
+
+private:
+ MyInputPanel *inputPanel;
+};
+
+//! [0]
+
+#endif // MYINPUTPANELCONTEXT_H
diff --git a/examples/tools/inputpanel/myinputpanelform.ui b/examples/tools/inputpanel/myinputpanelform.ui
new file mode 100644
index 0000000000..fe78442aff
--- /dev/null
+++ b/examples/tools/inputpanel/myinputpanelform.ui
@@ -0,0 +1,398 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MyInputPanelForm</class>
+ <widget class="QWidget" name="MyInputPanelForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>167</width>
+ <height>233</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Input Panel</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="panelButton_1">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>1</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>49</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="panelButton_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>2</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>50</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="panelButton_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>3</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>51</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="panelButton_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>4</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>52</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="panelButton_5">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>5</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>53</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QPushButton" name="panelButton_6">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>6</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>54</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="panelButton_7">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>7</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>55</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QPushButton" name="panelButton_8">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>8</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>56</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2">
+ <widget class="QPushButton" name="panelButton_9">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>9</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>57</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPushButton" name="panelButton_star">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>*</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>42</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QPushButton" name="panelButton_0">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>48</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="2">
+ <widget class="QPushButton" name="panelButton_hash">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>45</width>
+ <height>40</height>
+ </size>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>#</string>
+ </property>
+ <property name="buttonValue" stdset="0">
+ <char>
+ <unicode>35</unicode>
+ </char>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton">
+ <property name="font">
+ <font>
+ <pointsize>8</pointsize>
+ </font>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>closeButton</sender>
+ <signal>clicked()</signal>
+ <receiver>MyInputPanelForm</receiver>
+ <slot>hide()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>114</x>
+ <y>209</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>83</x>
+ <y>116</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/tools/plugandpaint/interfaces.h b/examples/tools/plugandpaint/interfaces.h
new file mode 100644
index 0000000000..785f3a1610
--- /dev/null
+++ b/examples/tools/plugandpaint/interfaces.h
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef INTERFACES_H
+#define INTERFACES_H
+
+#include <QtPlugin>
+
+QT_BEGIN_NAMESPACE
+class QImage;
+class QPainter;
+class QWidget;
+class QPainterPath;
+class QPoint;
+class QRect;
+class QString;
+class QStringList;
+QT_END_NAMESPACE
+
+//! [0]
+class BrushInterface
+{
+public:
+ virtual ~BrushInterface() {}
+
+ virtual QStringList brushes() const = 0;
+ virtual QRect mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos) = 0;
+ virtual QRect mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos) = 0;
+ virtual QRect mouseRelease(const QString &brush, QPainter &painter,
+ const QPoint &pos) = 0;
+};
+//! [0]
+
+//! [1]
+class ShapeInterface
+{
+public:
+ virtual ~ShapeInterface() {}
+
+ virtual QStringList shapes() const = 0;
+ virtual QPainterPath generateShape(const QString &shape,
+ QWidget *parent) = 0;
+};
+//! [1]
+
+//! [2]
+class FilterInterface
+{
+public:
+ virtual ~FilterInterface() {}
+
+ virtual QStringList filters() const = 0;
+ virtual QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent) = 0;
+};
+//! [2]
+
+QT_BEGIN_NAMESPACE
+//! [3] //! [4]
+Q_DECLARE_INTERFACE(BrushInterface,
+ "com.trolltech.PlugAndPaint.BrushInterface/1.0")
+//! [3]
+Q_DECLARE_INTERFACE(ShapeInterface,
+ "com.trolltech.PlugAndPaint.ShapeInterface/1.0")
+//! [5]
+Q_DECLARE_INTERFACE(FilterInterface,
+ "com.trolltech.PlugAndPaint.FilterInterface/1.0")
+//! [4] //! [5]
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/tools/plugandpaint/main.cpp b/examples/tools/plugandpaint/main.cpp
new file mode 100644
index 0000000000..f5ae1da83f
--- /dev/null
+++ b/examples/tools/plugandpaint/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include "mainwindow.h"
+#include <QtPlugin>
+#include <QApplication>
+
+QT_BEGIN_NAMESPACE
+Q_IMPORT_PLUGIN(pnp_basictools)
+QT_END_NAMESPACE
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/plugandpaint/mainwindow.cpp b/examples/tools/plugandpaint/mainwindow.cpp
new file mode 100644
index 0000000000..292cae1fe7
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.cpp
@@ -0,0 +1,309 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "interfaces.h"
+#include "mainwindow.h"
+#include "paintarea.h"
+#include "plugindialog.h"
+
+#include <QPluginLoader>
+#include <QTimer>
+
+#include <QScrollArea>
+#include <QMessageBox>
+#include <QActionGroup>
+#include <QAction>
+#include <QMenu>
+#include <QMenuBar>
+#include <QFileDialog>
+#include <QColorDialog>
+#include <QInputDialog>
+#include <QApplication>
+
+MainWindow::MainWindow() :
+ paintArea(new PaintArea),
+ scrollArea(new QScrollArea)
+{
+ scrollArea->setBackgroundRole(QPalette::Dark);
+ scrollArea->setWidget(paintArea);
+ setCentralWidget(scrollArea);
+
+ createActions();
+ createMenus();
+ loadPlugins();
+
+ setWindowTitle(tr("Plug & Paint"));
+
+ if (!brushActionGroup->actions().isEmpty())
+ brushActionGroup->actions().first()->trigger();
+
+ QTimer::singleShot(500, this, SLOT(aboutPlugins()));
+}
+
+void MainWindow::open()
+{
+ const QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"),
+ QDir::currentPath());
+ if (!fileName.isEmpty()) {
+ if (!paintArea->openImage(fileName)) {
+ QMessageBox::information(this, tr("Plug & Paint"),
+ tr("Cannot load %1.").arg(fileName));
+ return;
+ }
+ paintArea->adjustSize();
+ }
+}
+
+bool MainWindow::saveAs()
+{
+ const QString initialPath = QDir::currentPath() + "/untitled.png";
+
+ const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath);
+ if (fileName.isEmpty()) {
+ return false;
+ } else {
+ return paintArea->saveImage(fileName, "png");
+ }
+}
+
+void MainWindow::brushColor()
+{
+ const QColor newColor = QColorDialog::getColor(paintArea->brushColor());
+ if (newColor.isValid())
+ paintArea->setBrushColor(newColor);
+}
+
+void MainWindow::brushWidth()
+{
+ bool ok;
+ const int newWidth = QInputDialog::getInteger(this, tr("Plug & Paint"),
+ tr("Select brush width:"),
+ paintArea->brushWidth(),
+ 1, 50, 1, &ok);
+ if (ok)
+ paintArea->setBrushWidth(newWidth);
+}
+
+//! [0]
+void MainWindow::changeBrush()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(action->parent());
+ const QString brush = action->text();
+
+ paintArea->setBrush(iBrush, brush);
+}
+//! [0]
+
+//! [1]
+void MainWindow::insertShape()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(action->parent());
+
+ const QPainterPath path = iShape->generateShape(action->text(), this);
+ if (!path.isEmpty())
+ paintArea->insertShape(path);
+}
+//! [1]
+
+//! [2]
+void MainWindow::applyFilter()
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ FilterInterface *iFilter =
+ qobject_cast<FilterInterface *>(action->parent());
+
+ const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
+ this);
+ paintArea->setImage(image);
+}
+//! [2]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Plug & Paint"),
+ tr("The <b>Plug & Paint</b> example demonstrates how to write Qt "
+ "applications that can be extended through plugins."));
+}
+
+//! [3]
+void MainWindow::aboutPlugins()
+{
+ PluginDialog dialog(pluginsDir.path(), pluginFileNames, this);
+ dialog.exec();
+}
+//! [3]
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ brushColorAct = new QAction(tr("&Brush Color..."), this);
+ connect(brushColorAct, SIGNAL(triggered()), this, SLOT(brushColor()));
+
+ brushWidthAct = new QAction(tr("&Brush Width..."), this);
+ connect(brushWidthAct, SIGNAL(triggered()), this, SLOT(brushWidth()));
+
+ brushActionGroup = new QActionGroup(this);
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ aboutPluginsAct = new QAction(tr("About &Plugins"), this);
+ connect(aboutPluginsAct, SIGNAL(triggered()), this, SLOT(aboutPlugins()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ brushMenu = menuBar()->addMenu(tr("&Brush"));
+ brushMenu->addAction(brushColorAct);
+ brushMenu->addAction(brushWidthAct);
+ brushMenu->addSeparator();
+
+ shapesMenu = menuBar()->addMenu(tr("&Shapes"));
+
+ filterMenu = menuBar()->addMenu(tr("&Filter"));
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+ helpMenu->addAction(aboutPluginsAct);
+}
+
+//! [4]
+void MainWindow::loadPlugins()
+{
+ foreach (QObject *plugin, QPluginLoader::staticInstances())
+ populateMenus(plugin);
+//! [4] //! [5]
+
+ pluginsDir = QDir(qApp->applicationDirPath());
+
+#if defined(Q_OS_WIN)
+ if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
+ pluginsDir.cdUp();
+#elif defined(Q_OS_MAC)
+ if (pluginsDir.dirName() == "MacOS") {
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ pluginsDir.cdUp();
+ }
+#endif
+ pluginsDir.cd("plugins");
+//! [5]
+
+//! [6]
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (plugin) {
+ populateMenus(plugin);
+ pluginFileNames += fileName;
+//! [6] //! [7]
+ }
+//! [7] //! [8]
+ }
+//! [8]
+
+//! [9]
+ brushMenu->setEnabled(!brushActionGroup->actions().isEmpty());
+ shapesMenu->setEnabled(!shapesMenu->actions().isEmpty());
+ filterMenu->setEnabled(!filterMenu->actions().isEmpty());
+}
+//! [9]
+
+//! [10]
+void MainWindow::populateMenus(QObject *plugin)
+{
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
+ if (iBrush)
+ addToMenu(plugin, iBrush->brushes(), brushMenu, SLOT(changeBrush()),
+ brushActionGroup);
+
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
+ if (iShape)
+ addToMenu(plugin, iShape->shapes(), shapesMenu, SLOT(insertShape()));
+
+ FilterInterface *iFilter = qobject_cast<FilterInterface *>(plugin);
+ if (iFilter)
+ addToMenu(plugin, iFilter->filters(), filterMenu, SLOT(applyFilter()));
+}
+//! [10]
+
+void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
+ QMenu *menu, const char *member,
+ QActionGroup *actionGroup)
+{
+ foreach (QString text, texts) {
+ QAction *action = new QAction(text, plugin);
+ connect(action, SIGNAL(triggered()), this, member);
+ menu->addAction(action);
+
+ if (actionGroup) {
+ action->setCheckable(true);
+ actionGroup->addAction(action);
+ }
+ }
+}
diff --git a/examples/tools/plugandpaint/mainwindow.h b/examples/tools/plugandpaint/mainwindow.h
new file mode 100644
index 0000000000..526e3d5005
--- /dev/null
+++ b/examples/tools/plugandpaint/mainwindow.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QDir>
+#include <QMainWindow>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QActionGroup;
+class QMenu;
+class QScrollArea;
+QT_END_NAMESPACE
+class PaintArea;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void open();
+ bool saveAs();
+ void brushColor();
+ void brushWidth();
+ void changeBrush();
+ void insertShape();
+ void applyFilter();
+ void about();
+ void aboutPlugins();
+
+private:
+ void createActions();
+ void createMenus();
+ void loadPlugins();
+ void populateMenus(QObject *plugin);
+ void addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu,
+ const char *member, QActionGroup *actionGroup = 0);
+
+ PaintArea *paintArea;
+ QScrollArea *scrollArea;
+ QDir pluginsDir;
+ QStringList pluginFileNames;
+
+ QMenu *fileMenu;
+ QMenu *brushMenu;
+ QMenu *shapesMenu;
+ QMenu *filterMenu;
+ QMenu *helpMenu;
+ QActionGroup *brushActionGroup;
+ QAction *openAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *brushWidthAct;
+ QAction *brushColorAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+ QAction *aboutPluginsAct;
+};
+
+#endif
diff --git a/examples/tools/plugandpaint/paintarea.cpp b/examples/tools/plugandpaint/paintarea.cpp
new file mode 100644
index 0000000000..f6ace44ea5
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.cpp
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "interfaces.h"
+#include "paintarea.h"
+
+#include <QPainter>
+#include <QMouseEvent>
+
+PaintArea::PaintArea(QWidget *parent) :
+ QWidget(parent),
+ theImage(500, 400, QImage::Format_RGB32),
+ color(Qt::blue),
+ thickness(3),
+ brushInterface(0),
+ lastPos(-1, -1)
+{
+ setAttribute(Qt::WA_StaticContents);
+ setAttribute(Qt::WA_NoBackground);
+
+ theImage.fill(qRgb(255, 255, 255));
+}
+
+bool PaintArea::openImage(const QString &fileName)
+{
+ QImage image;
+ if (!image.load(fileName))
+ return false;
+
+ setImage(image);
+ return true;
+}
+
+bool PaintArea::saveImage(const QString &fileName, const char *fileFormat)
+{
+ return theImage.save(fileName, fileFormat);
+}
+
+void PaintArea::setImage(const QImage &image)
+{
+ theImage = image.convertToFormat(QImage::Format_RGB32);
+ update();
+ updateGeometry();
+}
+
+void PaintArea::insertShape(const QPainterPath &path)
+{
+ pendingPath = path;
+#ifndef QT_NO_CURSOR
+ setCursor(Qt::CrossCursor);
+#endif
+}
+
+void PaintArea::setBrushColor(const QColor &color)
+{
+ this->color = color;
+}
+
+void PaintArea::setBrushWidth(int width)
+{
+ thickness = width;
+}
+
+//! [0]
+void PaintArea::setBrush(BrushInterface *brushInterface, const QString &brush)
+{
+ this->brushInterface = brushInterface;
+ this->brush = brush;
+}
+//! [0]
+
+QSize PaintArea::sizeHint() const
+{
+ return theImage.size();
+}
+
+void PaintArea::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+ painter.drawImage(QPoint(0, 0), theImage);
+}
+
+void PaintArea::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ if (!pendingPath.isEmpty()) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+
+ const QRectF boundingRect = pendingPath.boundingRect();
+ QLinearGradient gradient(boundingRect.topRight(),
+ boundingRect.bottomLeft());
+ gradient.setColorAt(0.0, QColor(color.red(), color.green(),
+ color.blue(), 63));
+ gradient.setColorAt(1.0, QColor(color.red(), color.green(),
+ color.blue(), 191));
+ painter.setBrush(gradient);
+ painter.translate(event->pos() - boundingRect.center());
+ painter.drawPath(pendingPath);
+
+ pendingPath = QPainterPath();
+#ifndef QT_NO_CURSOR
+ unsetCursor();
+#endif
+ update();
+ } else {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ const QRect rect = brushInterface->mousePress(brush, painter,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = event->pos();
+ }
+ }
+}
+
+//! [1]
+void PaintArea::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && lastPos != QPoint(-1, -1)) {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ const QRect rect = brushInterface->mouseMove(brush, painter, lastPos,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = event->pos();
+ }
+}
+//! [1]
+
+void PaintArea::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && lastPos != QPoint(-1, -1)) {
+ if (brushInterface) {
+ QPainter painter(&theImage);
+ setupPainter(painter);
+ QRect rect = brushInterface->mouseRelease(brush, painter,
+ event->pos());
+ update(rect);
+ }
+
+ lastPos = QPoint(-1, -1);
+ }
+}
+
+void PaintArea::setupPainter(QPainter &painter)
+{
+ painter.setRenderHint(QPainter::Antialiasing, true);
+ painter.setPen(QPen(color, thickness, Qt::SolidLine, Qt::RoundCap,
+ Qt::RoundJoin));
+}
diff --git a/examples/tools/plugandpaint/paintarea.h b/examples/tools/plugandpaint/paintarea.h
new file mode 100644
index 0000000000..d1185b287c
--- /dev/null
+++ b/examples/tools/plugandpaint/paintarea.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PAINTAREA_H
+#define PAINTAREA_H
+
+#include <QColor>
+#include <QImage>
+#include <QPainterPath>
+#include <QWidget>
+
+class BrushInterface;
+
+class PaintArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PaintArea(QWidget *parent = 0);
+
+ bool openImage(const QString &fileName);
+ bool saveImage(const QString &fileName, const char *fileFormat);
+ void setImage(const QImage &image);
+ void insertShape(const QPainterPath &path);
+ void setBrushColor(const QColor &color);
+ void setBrushWidth(int width);
+ void setBrush(BrushInterface *brushInterface, const QString &brush);
+
+ QImage image() const { return theImage; }
+ QColor brushColor() const { return color; }
+ int brushWidth() const { return thickness; }
+ QSize sizeHint() const;
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private:
+ void setupPainter(QPainter &painter);
+
+ QImage theImage;
+ QColor color;
+ int thickness;
+
+ BrushInterface *brushInterface;
+ QString brush;
+ QPoint lastPos;
+
+ QPainterPath pendingPath;
+};
+
+#endif
diff --git a/examples/tools/plugandpaint/plugandpaint.pro b/examples/tools/plugandpaint/plugandpaint.pro
new file mode 100644
index 0000000000..9ed0402d05
--- /dev/null
+++ b/examples/tools/plugandpaint/plugandpaint.pro
@@ -0,0 +1,28 @@
+#! [0]
+HEADERS = interfaces.h \
+ mainwindow.h \
+ paintarea.h \
+ plugindialog.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ paintarea.cpp \
+ plugindialog.cpp
+symbian {
+ LIBS = -lpnp_basictools.lib
+} else {
+ LIBS = -L$${QT_BUILD_TREE}/examples/tools/plugandpaint/plugins -lpnp_basictools
+}
+
+if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
+ mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)_debug
+ win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d
+}
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaint
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/plugandpaint/plugindialog.cpp b/examples/tools/plugandpaint/plugindialog.cpp
new file mode 100644
index 0000000000..66a51ee8ae
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "interfaces.h"
+#include "plugindialog.h"
+
+#include <QPluginLoader>
+#include <QStringList>
+#include <QDir>
+
+#include <QLabel>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QHeaderView>
+
+PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames,
+ QWidget *parent) :
+ QDialog(parent),
+ label(new QLabel),
+ treeWidget(new QTreeWidget),
+ okButton(new QPushButton(tr("OK")))
+{
+ treeWidget->setAlternatingRowColors(false);
+ treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
+ treeWidget->setColumnCount(1);
+ treeWidget->header()->hide();
+
+ okButton->setDefault(true);
+
+ connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->setColumnStretch(0, 1);
+ mainLayout->setColumnStretch(2, 1);
+ mainLayout->addWidget(label, 0, 0, 1, 3);
+ mainLayout->addWidget(treeWidget, 1, 0, 1, 3);
+ mainLayout->addWidget(okButton, 2, 1);
+ setLayout(mainLayout);
+
+ interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ interfaceIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ featureIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
+
+ setWindowTitle(tr("Plugin Information"));
+ findPlugins(path, fileNames);
+}
+
+//! [0]
+void PluginDialog::findPlugins(const QString &path,
+ const QStringList &fileNames)
+{
+ label->setText(tr("Plug & Paint found the following plugins\n"
+ "(looked in %1):")
+ .arg(QDir::toNativeSeparators(path)));
+
+ const QDir dir(path);
+
+ foreach (QObject *plugin, QPluginLoader::staticInstances())
+ populateTreeWidget(plugin, tr("%1 (Static Plugin)")
+ .arg(plugin->metaObject()->className()));
+
+ foreach (QString fileName, fileNames) {
+ QPluginLoader loader(dir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (plugin)
+ populateTreeWidget(plugin, fileName);
+ }
+}
+//! [0]
+
+//! [1]
+void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text)
+{
+ QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget);
+ pluginItem->setText(0, text);
+ treeWidget->setItemExpanded(pluginItem, true);
+
+ QFont boldFont = pluginItem->font(0);
+ boldFont.setBold(true);
+ pluginItem->setFont(0, boldFont);
+
+ if (plugin) {
+ BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);
+ if (iBrush)
+ addItems(pluginItem, "BrushInterface", iBrush->brushes());
+
+ ShapeInterface *iShape = qobject_cast<ShapeInterface *>(plugin);
+ if (iShape)
+ addItems(pluginItem, "ShapeInterface", iShape->shapes());
+
+ FilterInterface *iFilter =
+ qobject_cast<FilterInterface *>(plugin);
+ if (iFilter)
+ addItems(pluginItem, "FilterInterface", iFilter->filters());
+ }
+}
+//! [1]
+
+void PluginDialog::addItems(QTreeWidgetItem *pluginItem,
+ const char *interfaceName,
+ const QStringList &features)
+{
+ QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem);
+ interfaceItem->setText(0, interfaceName);
+ interfaceItem->setIcon(0, interfaceIcon);
+
+ foreach (QString feature, features) {
+ if (feature.endsWith("..."))
+ feature.chop(3);
+ QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem);
+ featureItem->setText(0, feature);
+ featureItem->setIcon(0, featureIcon);
+ }
+}
diff --git a/examples/tools/plugandpaint/plugindialog.h b/examples/tools/plugandpaint/plugindialog.h
new file mode 100644
index 0000000000..36e79f5bf5
--- /dev/null
+++ b/examples/tools/plugandpaint/plugindialog.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLUGINDIALOG_H
+#define PLUGINDIALOG_H
+
+#include <QDialog>
+#include <QIcon>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QPushButton;
+class QStringList;
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+class PluginDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PluginDialog(const QString &path, const QStringList &fileNames,
+ QWidget *parent = 0);
+
+private:
+ void findPlugins(const QString &path, const QStringList &fileNames);
+ void populateTreeWidget(QObject *plugin, const QString &text);
+ void addItems(QTreeWidgetItem *pluginItem, const char *interfaceName,
+ const QStringList &features);
+
+ QLabel *label;
+ QTreeWidget *treeWidget;
+ QPushButton *okButton;
+ QIcon interfaceIcon;
+ QIcon featureIcon;
+};
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/basictools/basictools.pro b/examples/tools/plugandpaintplugins/basictools/basictools.pro
new file mode 100644
index 0000000000..6dc626be32
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictools.pro
@@ -0,0 +1,17 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin static
+INCLUDEPATH += ../..
+HEADERS = basictoolsplugin.h
+SOURCES = basictoolsplugin.cpp
+TARGET = $$qtLibraryTarget(pnp_basictools)
+DESTDIR = ../../plugandpaint/plugins
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS basictools.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaintplugins/basictools
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
new file mode 100644
index 0000000000..a35dae7ab9
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "basictoolsplugin.h"
+
+const float Pi = 3.14159f;
+
+//! [0]
+QStringList BasicToolsPlugin::brushes() const
+{
+ return QStringList() << tr("Pencil") << tr("Air Brush")
+ << tr("Random Letters");
+}
+//! [0]
+
+//! [1]
+QRect BasicToolsPlugin::mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos)
+{
+ return mouseMove(brush, painter, pos, pos);
+}
+//! [1]
+
+//! [2]
+QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos)
+{
+ painter.save();
+
+ int rad = painter.pen().width() / 2;
+ QRect boundingRect = QRect(oldPos, newPos).normalized()
+ .adjusted(-rad, -rad, +rad, +rad);
+ QColor color = painter.pen().color();
+ int thickness = painter.pen().width();
+ QColor transparentColor(color.red(), color.green(), color.blue(), 0);
+//! [2] //! [3]
+
+ if (brush == tr("Pencil")) {
+ painter.drawLine(oldPos, newPos);
+ } else if (brush == tr("Air Brush")) {
+ int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;
+
+ painter.setBrush(QBrush(color, Qt::Dense6Pattern));
+ painter.setPen(Qt::NoPen);
+
+ for (int i = 0; i < numSteps; ++i) {
+ int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
+ int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);
+
+ painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
+ thickness, thickness);
+ }
+ } else if (brush == tr("Random Letters")) {
+ QChar ch('A' + (qrand() % 26));
+
+ QFont biggerFont = painter.font();
+ biggerFont.setBold(true);
+ biggerFont.setPointSize(biggerFont.pointSize() + thickness);
+ painter.setFont(biggerFont);
+
+ painter.drawText(newPos, QString(ch));
+
+ QFontMetrics metrics(painter.font());
+ boundingRect = metrics.boundingRect(ch);
+ boundingRect.translate(newPos);
+ boundingRect.adjust(-10, -10, +10, +10);
+ }
+ painter.restore();
+ return boundingRect;
+}
+//! [3]
+
+//! [4]
+QRect BasicToolsPlugin::mouseRelease(const QString & /* brush */,
+ QPainter & /* painter */,
+ const QPoint & /* pos */)
+{
+ return QRect(0, 0, 0, 0);
+}
+//! [4]
+
+//! [5]
+QStringList BasicToolsPlugin::shapes() const
+{
+ return QStringList() << tr("Circle") << tr("Star") << tr("Text...");
+}
+//! [5]
+
+//! [6]
+QPainterPath BasicToolsPlugin::generateShape(const QString &shape,
+ QWidget *parent)
+{
+ QPainterPath path;
+
+ if (shape == tr("Circle")) {
+ path.addEllipse(0, 0, 50, 50);
+ } else if (shape == tr("Star")) {
+ path.moveTo(90, 50);
+ for (int i = 1; i < 5; ++i) {
+ path.lineTo(50 + 40 * cos(0.8 * i * Pi),
+ 50 + 40 * sin(0.8 * i * Pi));
+ }
+ path.closeSubpath();
+ } else if (shape == tr("Text...")) {
+ QString text = QInputDialog::getText(parent, tr("Text Shape"),
+ tr("Enter text:"),
+ QLineEdit::Normal, tr("Qt"));
+ if (!text.isEmpty()) {
+ QFont timesFont("Times", 50);
+ timesFont.setStyleStrategy(QFont::ForceOutline);
+ path.addText(0, 0, timesFont, text);
+ }
+ }
+
+ return path;
+}
+//! [6]
+
+//! [7]
+QStringList BasicToolsPlugin::filters() const
+{
+ return QStringList() << tr("Invert Pixels") << tr("Swap RGB")
+ << tr("Grayscale");
+}
+//! [7]
+
+//! [8]
+QImage BasicToolsPlugin::filterImage(const QString &filter, const QImage &image,
+ QWidget * /* parent */)
+{
+ QImage result = image.convertToFormat(QImage::Format_RGB32);
+
+ if (filter == tr("Invert Pixels")) {
+ result.invertPixels();
+ } else if (filter == tr("Swap RGB")) {
+ result = result.rgbSwapped();
+ } else if (filter == tr("Grayscale")) {
+ for (int y = 0; y < result.height(); ++y) {
+ for (int x = 0; x < result.width(); ++x) {
+ int pixel = result.pixel(x, y);
+ int gray = qGray(pixel);
+ int alpha = qAlpha(pixel);
+ result.setPixel(x, y, qRgba(gray, gray, gray, alpha));
+ }
+ }
+ }
+ return result;
+}
+//! [8]
+
+QT_BEGIN_NAMESPACE
+//! [9]
+Q_EXPORT_PLUGIN2(pnp_basictools, BasicToolsPlugin)
+//! [9]
+QT_END_NAMESPACE
diff --git a/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h
new file mode 100644
index 0000000000..79bcc5a088
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/basictools/basictoolsplugin.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BASICTOOLSPLUGIN_H
+#define BASICTOOLSPLUGIN_H
+
+#include <QRect>
+#include <QObject>
+#include <QStringList>
+#include <QPainterPath>
+#include <QImage>
+
+//! [0]
+#include <plugandpaint/interfaces.h>
+
+//! [1]
+class BasicToolsPlugin : public QObject,
+ public BrushInterface,
+ public ShapeInterface,
+ public FilterInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(BrushInterface ShapeInterface FilterInterface)
+//! [0]
+
+//! [2]
+public:
+//! [1]
+ // BrushInterface
+ QStringList brushes() const;
+ QRect mousePress(const QString &brush, QPainter &painter,
+ const QPoint &pos);
+ QRect mouseMove(const QString &brush, QPainter &painter,
+ const QPoint &oldPos, const QPoint &newPos);
+ QRect mouseRelease(const QString &brush, QPainter &painter,
+ const QPoint &pos);
+
+ // ShapeInterface
+ QStringList shapes() const;
+ QPainterPath generateShape(const QString &shape, QWidget *parent);
+
+ // FilterInterface
+ QStringList filters() const;
+ QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent);
+//! [3]
+};
+//! [2] //! [3]
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro b/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro
new file mode 100644
index 0000000000..91c9ce94b6
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafilters.pro
@@ -0,0 +1,19 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = extrafiltersplugin.h
+SOURCES = extrafiltersplugin.cpp
+TARGET = $$qtLibraryTarget(pnp_extrafilters)
+DESTDIR = ../../plugandpaint/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaint/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS extrafilters.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaintplugins/extrafilters
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp
new file mode 100644
index 0000000000..9f8ca48650
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+#include <stdlib.h>
+
+#include "extrafiltersplugin.h"
+
+QStringList ExtraFiltersPlugin::filters() const
+{
+ return QStringList() << tr("Flip Horizontally") << tr("Flip Vertically")
+ << tr("Smudge...") << tr("Threshold...");
+}
+
+QImage ExtraFiltersPlugin::filterImage(const QString &filter,
+ const QImage &image, QWidget *parent)
+{
+ QImage original = image.convertToFormat(QImage::Format_RGB32);
+ QImage result = original;
+
+ if (filter == tr("Flip Horizontally")) {
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(original.width() - x - 1, y);
+ result.setPixel(x, y, pixel);
+ }
+ }
+ } else if (filter == tr("Flip Vertically")) {
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(x, original.height() - y - 1);
+ result.setPixel(x, y, pixel);
+ }
+ }
+ } else if (filter == tr("Smudge...")) {
+ bool ok;
+ int numIters = QInputDialog::getInteger(parent, tr("Smudge Filter"),
+ tr("Enter number of iterations:"),
+ 5, 1, 20, 1, &ok);
+ if (ok) {
+ for (int i = 0; i < numIters; ++i) {
+ for (int y = 1; y < original.height() - 1; ++y) {
+ for (int x = 1; x < original.width() - 1; ++x) {
+ int p1 = original.pixel(x, y);
+ int p2 = original.pixel(x, y + 1);
+ int p3 = original.pixel(x, y - 1);
+ int p4 = original.pixel(x + 1, y);
+ int p5 = original.pixel(x - 1, y);
+
+ int red = (qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)
+ + qRed(p5)) / 5;
+ int green = (qGreen(p1) + qGreen(p2) + qGreen(p3)
+ + qGreen(p4) + qGreen(p5)) / 5;
+ int blue = (qBlue(p1) + qBlue(p2) + qBlue(p3)
+ + qBlue(p4) + qBlue(p5)) / 5;
+ int alpha = (qAlpha(p1) + qAlpha(p2) + qAlpha(p3)
+ + qAlpha(p4) + qAlpha(p5)) / 5;
+
+ result.setPixel(x, y, qRgba(red, green, blue, alpha));
+ }
+ }
+ }
+ }
+ } else if (filter == tr("Threshold...")) {
+ bool ok;
+ int threshold = QInputDialog::getInteger(parent, tr("Threshold Filter"),
+ tr("Enter threshold:"),
+ 10, 1, 256, 1, &ok);
+ if (ok) {
+ int factor = 256 / threshold;
+ for (int y = 0; y < original.height(); ++y) {
+ for (int x = 0; x < original.width(); ++x) {
+ int pixel = original.pixel(x, y);
+ result.setPixel(x, y, qRgba(qRed(pixel) / factor * factor,
+ qGreen(pixel) / factor * factor,
+ qBlue(pixel) / factor * factor,
+ qAlpha(pixel)));
+ }
+ }
+ }
+ }
+ return result;
+}
+
+Q_EXPORT_PLUGIN2(pnp_extrafilters, ExtraFiltersPlugin)
diff --git a/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
new file mode 100644
index 0000000000..db5679f016
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/extrafilters/extrafiltersplugin.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EXTRAFILTERSPLUGIN_H
+#define EXTRAFILTERSPLUGIN_H
+
+//! [0]
+#include <QObject>
+#include <QStringList>
+#include <QImage>
+
+#include <plugandpaint/interfaces.h>
+
+class ExtraFiltersPlugin : public QObject, public FilterInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(FilterInterface)
+
+public:
+ QStringList filters() const;
+ QImage filterImage(const QString &filter, const QImage &image,
+ QWidget *parent);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/plugandpaintplugins/plugandpaintplugins.pro b/examples/tools/plugandpaintplugins/plugandpaintplugins.pro
new file mode 100644
index 0000000000..8309f01191
--- /dev/null
+++ b/examples/tools/plugandpaintplugins/plugandpaintplugins.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = basictools \
+ extrafilters
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaintplugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugandpaintplugins.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/plugandpaintplugins
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/regexp/main.cpp b/examples/tools/regexp/main.cpp
new file mode 100644
index 0000000000..fe3fda64f0
--- /dev/null
+++ b/examples/tools/regexp/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "regexpdialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ RegExpDialog dialog;
+ dialog.show();
+ return dialog.exec();
+}
diff --git a/examples/tools/regexp/regexp.pro b/examples/tools/regexp/regexp.pro
new file mode 100644
index 0000000000..ef99a090e7
--- /dev/null
+++ b/examples/tools/regexp/regexp.pro
@@ -0,0 +1,11 @@
+HEADERS = regexpdialog.h
+SOURCES = regexpdialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/regexp
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS regexp.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/regexp
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/regexp/regexpdialog.cpp b/examples/tools/regexp/regexpdialog.cpp
new file mode 100644
index 0000000000..583c384bdd
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+
+#include "regexpdialog.h"
+
+RegExpDialog::RegExpDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ patternComboBox = new QComboBox;
+ patternComboBox->setEditable(true);
+ patternComboBox->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Preferred);
+
+ patternLabel = new QLabel(tr("&Pattern:"));
+ patternLabel->setBuddy(patternComboBox);
+
+ escapedPatternLineEdit = new QLineEdit;
+ escapedPatternLineEdit->setReadOnly(true);
+ QPalette palette = escapedPatternLineEdit->palette();
+ palette.setBrush(QPalette::Base,
+ palette.brush(QPalette::Disabled, QPalette::Base));
+ escapedPatternLineEdit->setPalette(palette);
+
+ escapedPatternLabel = new QLabel(tr("&Escaped Pattern:"));
+ escapedPatternLabel->setBuddy(escapedPatternLineEdit);
+
+ syntaxComboBox = new QComboBox;
+ syntaxComboBox->addItem(tr("Regular expression v1"), QRegExp::RegExp);
+ syntaxComboBox->addItem(tr("Regular expression v2"), QRegExp::RegExp2);
+ syntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
+ syntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
+ syntaxComboBox->addItem(tr("W3C Xml Schema 1.1"), QRegExp::W3CXmlSchema11);
+
+ syntaxLabel = new QLabel(tr("&Pattern Syntax:"));
+ syntaxLabel->setBuddy(syntaxComboBox);
+
+ textComboBox = new QComboBox;
+ textComboBox->setEditable(true);
+ textComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+
+ textLabel = new QLabel(tr("&Text:"));
+ textLabel->setBuddy(textComboBox);
+
+ caseSensitiveCheckBox = new QCheckBox(tr("Case &Sensitive"));
+ caseSensitiveCheckBox->setChecked(true);
+ minimalCheckBox = new QCheckBox(tr("&Minimal"));
+
+ indexLabel = new QLabel(tr("Index of Match:"));
+ indexEdit = new QLineEdit;
+ indexEdit->setReadOnly(true);
+
+ matchedLengthLabel = new QLabel(tr("Matched Length:"));
+ matchedLengthEdit = new QLineEdit;
+ matchedLengthEdit->setReadOnly(true);
+
+ for (int i = 0; i < MaxCaptures; ++i) {
+ captureLabels[i] = new QLabel(tr("Capture %1:").arg(i));
+ captureEdits[i] = new QLineEdit;
+ captureEdits[i]->setReadOnly(true);
+ }
+ captureLabels[0]->setText(tr("Match:"));
+
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(caseSensitiveCheckBox);
+ checkBoxLayout->addWidget(minimalCheckBox);
+ checkBoxLayout->addStretch(1);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(patternLabel, 0, 0);
+ mainLayout->addWidget(patternComboBox, 0, 1);
+ mainLayout->addWidget(escapedPatternLabel, 1, 0);
+ mainLayout->addWidget(escapedPatternLineEdit, 1, 1);
+ mainLayout->addWidget(syntaxLabel, 2, 0);
+ mainLayout->addWidget(syntaxComboBox, 2, 1);
+ mainLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ mainLayout->addWidget(textLabel, 4, 0);
+ mainLayout->addWidget(textComboBox, 4, 1);
+ mainLayout->addWidget(indexLabel, 5, 0);
+ mainLayout->addWidget(indexEdit, 5, 1);
+ mainLayout->addWidget(matchedLengthLabel, 6, 0);
+ mainLayout->addWidget(matchedLengthEdit, 6, 1);
+
+ for (int j = 0; j < MaxCaptures; ++j) {
+ mainLayout->addWidget(captureLabels[j], 7 + j, 0);
+ mainLayout->addWidget(captureEdits[j], 7 + j, 1);
+ }
+ setLayout(mainLayout);
+
+ connect(patternComboBox, SIGNAL(editTextChanged(QString)),
+ this, SLOT(refresh()));
+ connect(textComboBox, SIGNAL(editTextChanged(QString)),
+ this, SLOT(refresh()));
+ connect(caseSensitiveCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(refresh()));
+ connect(minimalCheckBox, SIGNAL(toggled(bool)), this, SLOT(refresh()));
+ connect(syntaxComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(refresh()));
+
+ patternComboBox->addItem(tr("[A-Za-z_]+([A-Za-z_0-9]*)"));
+ textComboBox->addItem(tr("(10 + delta4) * 32"));
+
+ setWindowTitle(tr("RegExp"));
+ setFixedHeight(sizeHint().height());
+ refresh();
+}
+
+void RegExpDialog::refresh()
+{
+ setUpdatesEnabled(false);
+
+ QString pattern = patternComboBox->currentText();
+ QString text = textComboBox->currentText();
+
+ QString escaped = pattern;
+ escaped.replace("\\", "\\\\");
+ escaped.replace("\"", "\\\"");
+ escaped.prepend("\"");
+ escaped.append("\"");
+ escapedPatternLineEdit->setText(escaped);
+
+ QRegExp rx(pattern);
+ Qt::CaseSensitivity cs = Qt::CaseInsensitive;
+ if (caseSensitiveCheckBox->isChecked())
+ cs = Qt::CaseSensitive;
+ rx.setCaseSensitivity(cs);
+ rx.setMinimal(minimalCheckBox->isChecked());
+ QRegExp::PatternSyntax syntax = QRegExp::PatternSyntax(
+ syntaxComboBox->itemData(syntaxComboBox->currentIndex()).toInt());
+ rx.setPatternSyntax(syntax);
+
+ QPalette palette = patternComboBox->palette();
+ if (rx.isValid()) {
+ palette.setColor(QPalette::Text,
+ textComboBox->palette().color(QPalette::Text));
+ } else {
+ palette.setColor(QPalette::Text, Qt::red);
+ }
+ patternComboBox->setPalette(palette);
+
+ indexEdit->setText(QString::number(rx.indexIn(text)));
+ matchedLengthEdit->setText(QString::number(rx.matchedLength()));
+ for (int i = 0; i < MaxCaptures; ++i) {
+ captureLabels[i]->setEnabled(i <= rx.captureCount());
+ captureEdits[i]->setEnabled(i <= rx.captureCount());
+ captureEdits[i]->setText(rx.cap(i));
+ }
+
+ setUpdatesEnabled(true);
+}
diff --git a/examples/tools/regexp/regexpdialog.h b/examples/tools/regexp/regexpdialog.h
new file mode 100644
index 0000000000..c157668cd1
--- /dev/null
+++ b/examples/tools/regexp/regexpdialog.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef REGEXPDIALOG_H
+#define REGEXPDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QLabel;
+class QLineEdit;
+QT_END_NAMESPACE
+
+class RegExpDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ RegExpDialog(QWidget *parent = 0);
+
+private slots:
+ void refresh();
+
+private:
+ QLabel *patternLabel;
+ QLabel *escapedPatternLabel;
+ QLabel *syntaxLabel;
+ QLabel *textLabel;
+ QComboBox *patternComboBox;
+ QLineEdit *escapedPatternLineEdit;
+ QComboBox *textComboBox;
+ QCheckBox *caseSensitiveCheckBox;
+ QCheckBox *minimalCheckBox;
+ QComboBox *syntaxComboBox;
+
+ QLabel *indexLabel;
+ QLabel *matchedLengthLabel;
+ QLineEdit *indexEdit;
+ QLineEdit *matchedLengthEdit;
+
+ enum { MaxCaptures = 6 };
+ QLabel *captureLabels[MaxCaptures];
+ QLineEdit *captureEdits[MaxCaptures];
+};
+
+#endif
diff --git a/examples/tools/settingseditor/inifiles/licensepage.ini b/examples/tools/settingseditor/inifiles/licensepage.ini
new file mode 100644
index 0000000000..608d1b7885
--- /dev/null
+++ b/examples/tools/settingseditor/inifiles/licensepage.ini
@@ -0,0 +1,46 @@
+[Field%201]
+Bottom=89
+Flags=MULTILINE|VSCROLL|READONLY
+Left=4
+Right=296
+State=No license agreement file found. Please contact support.
+Top=14
+Type=Text
+
+[Field%202]
+Bottom=8
+Left=4
+Right=294
+Text=Press Page Down to see the rest of the agreement.
+Top=0
+Type=Label
+
+[Field%203]
+Bottom=111
+Left=4
+Right=297
+Text=If you accept the terms of the agreement, select the first option below. You must accept the agreement to install this software. Click Next to continue.
+Top=92
+Type=Label
+
+[Field%204]
+Bottom=129
+Flags=GROUP|NOTIFY
+Left=4
+Right=299
+Text=I &accept the terms in the License Agreement
+Top=120
+Type=RadioButton
+
+[Field%205]
+Bottom=140
+Flags=NOTIFY
+Left=4
+Right=300
+State=1
+Text=I &do not accept the terms in the License Agreement
+Top=129
+Type=RadioButton
+
+[Settings]
+NumFields=5
diff --git a/examples/tools/settingseditor/inifiles/qsa.ini b/examples/tools/settingseditor/inifiles/qsa.ini
new file mode 100644
index 0000000000..56a2964ee5
--- /dev/null
+++ b/examples/tools/settingseditor/inifiles/qsa.ini
@@ -0,0 +1,26 @@
+[Field%201]
+Bottom=65
+Left=0
+Right=299
+Text=QSA Build Options
+Top=9
+Type=Groupbox
+
+[Field%202]
+Bottom=37
+Left=20
+Right=284
+Text=Don't compile QSA Workbench into QSA.
+Top=27
+Type=Checkbox
+
+[Field%203]
+Bottom=56
+Left=20
+Right=247
+Text=Don't compile QSA Workbench nor QSA Editor into QSA.
+Top=45
+Type=Checkbox
+
+[Settings]
+NumFields=3
diff --git a/examples/tools/settingseditor/locationdialog.cpp b/examples/tools/settingseditor/locationdialog.cpp
new file mode 100644
index 0000000000..911392630b
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.cpp
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "locationdialog.h"
+
+LocationDialog::LocationDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ formatComboBox = new QComboBox;
+ formatComboBox->addItem(tr("Native"));
+ formatComboBox->addItem(tr("INI"));
+
+ scopeComboBox = new QComboBox;
+ scopeComboBox->addItem(tr("User"));
+ scopeComboBox->addItem(tr("System"));
+
+ organizationComboBox = new QComboBox;
+ organizationComboBox->addItem(tr("Trolltech"));
+ organizationComboBox->setEditable(true);
+
+ applicationComboBox = new QComboBox;
+ applicationComboBox->addItem(tr("Any"));
+ applicationComboBox->addItem(tr("Application Example"));
+ applicationComboBox->addItem(tr("Assistant"));
+ applicationComboBox->addItem(tr("Designer"));
+ applicationComboBox->addItem(tr("Linguist"));
+ applicationComboBox->setEditable(true);
+ applicationComboBox->setCurrentIndex(3);
+
+ formatLabel = new QLabel(tr("&Format:"));
+ formatLabel->setBuddy(formatComboBox);
+
+ scopeLabel = new QLabel(tr("&Scope:"));
+ scopeLabel->setBuddy(scopeComboBox);
+
+ organizationLabel = new QLabel(tr("&Organization:"));
+ organizationLabel->setBuddy(organizationComboBox);
+
+ applicationLabel = new QLabel(tr("&Application:"));
+ applicationLabel->setBuddy(applicationComboBox);
+
+ locationsGroupBox = new QGroupBox(tr("Setting Locations"));
+
+ QStringList labels;
+ labels << tr("Location") << tr("Access");
+
+ locationsTable = new QTableWidget;
+ locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);
+ locationsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
+ locationsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ locationsTable->setColumnCount(2);
+ locationsTable->setHorizontalHeaderLabels(labels);
+ locationsTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
+ locationsTable->horizontalHeader()->resizeSection(1, 180);
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(formatComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateLocationsTable()));
+ connect(scopeComboBox, SIGNAL(activated(int)),
+ this, SLOT(updateLocationsTable()));
+ connect(organizationComboBox->lineEdit(),
+ SIGNAL(editingFinished()),
+ this, SLOT(updateLocationsTable()));
+ connect(applicationComboBox->lineEdit(),
+ SIGNAL(editingFinished()),
+ this, SLOT(updateLocationsTable()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ QVBoxLayout *locationsLayout = new QVBoxLayout;
+ locationsLayout->addWidget(locationsTable);
+ locationsGroupBox->setLayout(locationsLayout);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(formatLabel, 0, 0);
+ mainLayout->addWidget(formatComboBox, 0, 1);
+ mainLayout->addWidget(scopeLabel, 1, 0);
+ mainLayout->addWidget(scopeComboBox, 1, 1);
+ mainLayout->addWidget(organizationLabel, 2, 0);
+ mainLayout->addWidget(organizationComboBox, 2, 1);
+ mainLayout->addWidget(applicationLabel, 3, 0);
+ mainLayout->addWidget(applicationComboBox, 3, 1);
+ mainLayout->addWidget(locationsGroupBox, 4, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 5, 0, 1, 2);
+ setLayout(mainLayout);
+
+ updateLocationsTable();
+
+ setWindowTitle(tr("Open Application Settings"));
+ resize(650, 400);
+}
+
+QSettings::Format LocationDialog::format() const
+{
+ if (formatComboBox->currentIndex() == 0)
+ return QSettings::NativeFormat;
+ else
+ return QSettings::IniFormat;
+}
+
+QSettings::Scope LocationDialog::scope() const
+{
+ if (scopeComboBox->currentIndex() == 0)
+ return QSettings::UserScope;
+ else
+ return QSettings::SystemScope;
+}
+
+QString LocationDialog::organization() const
+{
+ return organizationComboBox->currentText();
+}
+
+QString LocationDialog::application() const
+{
+ if (applicationComboBox->currentText() == tr("Any"))
+ return "";
+ else
+ return applicationComboBox->currentText();
+}
+
+void LocationDialog::updateLocationsTable()
+{
+ locationsTable->setUpdatesEnabled(false);
+ locationsTable->setRowCount(0);
+
+ for (int i = 0; i < 2; ++i) {
+ if (i == 0 && scope() == QSettings::SystemScope)
+ continue;
+
+ QSettings::Scope actualScope = (i == 0) ? QSettings::UserScope
+ : QSettings::SystemScope;
+ for (int j = 0; j < 2; ++j) {
+ if (j == 0 && application().isEmpty())
+ continue;
+
+ QString actualApplication;
+ if (j == 0)
+ actualApplication = application();
+ QSettings settings(format(), actualScope, organization(),
+ actualApplication);
+
+ int row = locationsTable->rowCount();
+ locationsTable->setRowCount(row + 1);
+
+ QTableWidgetItem *item0 = new QTableWidgetItem;
+ item0->setText(settings.fileName());
+
+ QTableWidgetItem *item1 = new QTableWidgetItem;
+ bool disable = (settings.childKeys().isEmpty()
+ && settings.childGroups().isEmpty());
+
+ if (row == 0) {
+ if (settings.isWritable()) {
+ item1->setText(tr("Read-write"));
+ disable = false;
+ } else {
+ item1->setText(tr("Read-only"));
+ }
+ buttonBox->button(QDialogButtonBox::Ok)->setDisabled(disable);
+ } else {
+ item1->setText(tr("Read-only fallback"));
+ }
+
+ if (disable) {
+ item0->setFlags(item0->flags() & ~Qt::ItemIsEnabled);
+ item1->setFlags(item1->flags() & ~Qt::ItemIsEnabled);
+ }
+
+ locationsTable->setItem(row, 0, item0);
+ locationsTable->setItem(row, 1, item1);
+ }
+ }
+ locationsTable->setUpdatesEnabled(true);
+}
diff --git a/examples/tools/settingseditor/locationdialog.h b/examples/tools/settingseditor/locationdialog.h
new file mode 100644
index 0000000000..a8a20e460f
--- /dev/null
+++ b/examples/tools/settingseditor/locationdialog.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LOCATIONDIALOG_H
+#define LOCATIONDIALOG_H
+
+#include <QDialog>
+#include <QSettings>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QTableWidget;
+QT_END_NAMESPACE
+
+class LocationDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ LocationDialog(QWidget *parent = 0);
+
+ QSettings::Format format() const;
+ QSettings::Scope scope() const;
+ QString organization() const;
+ QString application() const;
+
+private slots:
+ void updateLocationsTable();
+
+private:
+ QLabel *formatLabel;
+ QLabel *scopeLabel;
+ QLabel *organizationLabel;
+ QLabel *applicationLabel;
+ QComboBox *formatComboBox;
+ QComboBox *scopeComboBox;
+ QComboBox *organizationComboBox;
+ QComboBox *applicationComboBox;
+ QGroupBox *locationsGroupBox;
+ QTableWidget *locationsTable;
+ QDialogButtonBox *buttonBox;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/main.cpp b/examples/tools/settingseditor/main.cpp
new file mode 100644
index 0000000000..923c1f8514
--- /dev/null
+++ b/examples/tools/settingseditor/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/tools/settingseditor/mainwindow.cpp b/examples/tools/settingseditor/mainwindow.cpp
new file mode 100644
index 0000000000..4b8bc4e2b8
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.cpp
@@ -0,0 +1,222 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "locationdialog.h"
+#include "mainwindow.h"
+#include "settingstree.h"
+
+MainWindow::MainWindow()
+{
+ settingsTree = new SettingsTree;
+ setCentralWidget(settingsTree);
+
+ locationDialog = 0;
+
+ createActions();
+ createMenus();
+
+ autoRefreshAct->setChecked(true);
+ fallbacksAct->setChecked(true);
+
+ setWindowTitle(tr("Settings Editor"));
+ resize(500, 600);
+}
+
+void MainWindow::openSettings()
+{
+ if (!locationDialog)
+ locationDialog = new LocationDialog(this);
+
+ if (locationDialog->exec()) {
+ QSettings *settings = new QSettings(locationDialog->format(),
+ locationDialog->scope(),
+ locationDialog->organization(),
+ locationDialog->application());
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(true);
+ }
+}
+
+void MainWindow::openIniFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open INI File"),
+ "", tr("INI Files (*.ini *.conf)"));
+ if (!fileName.isEmpty()) {
+ QSettings *settings = new QSettings(fileName, QSettings::IniFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::openPropertyList()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Property List"),
+ "", tr("Property List Files (*.plist)"));
+ if (!fileName.isEmpty()) {
+ QSettings *settings = new QSettings(fileName, QSettings::NativeFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::openRegistryPath()
+{
+ QString path = QInputDialog::getText(this, tr("Open Registry Path"),
+ tr("Enter the path in the Windows registry:"),
+ QLineEdit::Normal, "HKEY_CURRENT_USER\\");
+ if (!path.isEmpty()) {
+ QSettings *settings = new QSettings(path, QSettings::NativeFormat);
+ setSettingsObject(settings);
+ fallbacksAct->setEnabled(false);
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Settings Editor"),
+ tr("The <b>Settings Editor</b> example shows how to access "
+ "application settings using Qt."));
+}
+
+void MainWindow::createActions()
+{
+ openSettingsAct = new QAction(tr("&Open Application Settings..."), this);
+ openSettingsAct->setShortcuts(QKeySequence::Open);
+ connect(openSettingsAct, SIGNAL(triggered()), this, SLOT(openSettings()));
+
+ openIniFileAct = new QAction(tr("Open I&NI File..."), this);
+ openIniFileAct->setShortcut(tr("Ctrl+N"));
+ connect(openIniFileAct, SIGNAL(triggered()), this, SLOT(openIniFile()));
+
+ openPropertyListAct = new QAction(tr("Open Mac &Property List..."), this);
+ openPropertyListAct->setShortcut(tr("Ctrl+P"));
+ connect(openPropertyListAct, SIGNAL(triggered()),
+ this, SLOT(openPropertyList()));
+
+ openRegistryPathAct = new QAction(tr("Open Windows &Registry Path..."),
+ this);
+ openRegistryPathAct->setShortcut(tr("Ctrl+G"));
+ connect(openRegistryPathAct, SIGNAL(triggered()),
+ this, SLOT(openRegistryPath()));
+
+ refreshAct = new QAction(tr("&Refresh"), this);
+ refreshAct->setShortcut(tr("Ctrl+R"));
+ refreshAct->setEnabled(false);
+ connect(refreshAct, SIGNAL(triggered()), settingsTree, SLOT(refresh()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ autoRefreshAct = new QAction(tr("&Auto-Refresh"), this);
+ autoRefreshAct->setShortcut(tr("Ctrl+A"));
+ autoRefreshAct->setCheckable(true);
+ autoRefreshAct->setEnabled(false);
+ connect(autoRefreshAct, SIGNAL(triggered(bool)),
+ settingsTree, SLOT(setAutoRefresh(bool)));
+ connect(autoRefreshAct, SIGNAL(triggered(bool)),
+ refreshAct, SLOT(setDisabled(bool)));
+
+ fallbacksAct = new QAction(tr("&Fallbacks"), this);
+ fallbacksAct->setShortcut(tr("Ctrl+F"));
+ fallbacksAct->setCheckable(true);
+ fallbacksAct->setEnabled(false);
+ connect(fallbacksAct, SIGNAL(triggered(bool)),
+ settingsTree, SLOT(setFallbacksEnabled(bool)));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+#ifndef Q_WS_MAC
+ openPropertyListAct->setEnabled(false);
+#endif
+#ifndef Q_WS_WIN
+ openRegistryPathAct->setEnabled(false);
+#endif
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openSettingsAct);
+ fileMenu->addAction(openIniFileAct);
+ fileMenu->addAction(openPropertyListAct);
+ fileMenu->addAction(openRegistryPathAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(refreshAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ optionsMenu = menuBar()->addMenu(tr("&Options"));
+ optionsMenu->addAction(autoRefreshAct);
+ optionsMenu->addAction(fallbacksAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+
+void MainWindow::setSettingsObject(QSettings *settings)
+{
+ settings->setFallbacksEnabled(fallbacksAct->isChecked());
+ settingsTree->setSettingsObject(settings);
+
+ refreshAct->setEnabled(true);
+ autoRefreshAct->setEnabled(true);
+
+ QString niceName = settings->fileName();
+ niceName.replace("\\", "/");
+ int pos = niceName.lastIndexOf("/");
+ if (pos != -1)
+ niceName.remove(0, pos + 1);
+
+ if (!settings->isWritable())
+ niceName = tr("%1 (read only)").arg(niceName);
+
+ setWindowTitle(tr("%1 - %2").arg(niceName).arg(tr("Settings Editor")));
+}
diff --git a/examples/tools/settingseditor/mainwindow.h b/examples/tools/settingseditor/mainwindow.h
new file mode 100644
index 0000000000..6d997fa759
--- /dev/null
+++ b/examples/tools/settingseditor/mainwindow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QMenu;
+class QSettings;
+QT_END_NAMESPACE
+class LocationDialog;
+class SettingsTree;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void openSettings();
+ void openIniFile();
+ void openPropertyList();
+ void openRegistryPath();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ void setSettingsObject(QSettings *settings);
+
+ SettingsTree *settingsTree;
+ LocationDialog *locationDialog;
+
+ QMenu *fileMenu;
+ QMenu *optionsMenu;
+ QMenu *helpMenu;
+ QAction *openSettingsAct;
+ QAction *openIniFileAct;
+ QAction *openPropertyListAct;
+ QAction *openRegistryPathAct;
+ QAction *refreshAct;
+ QAction *exitAct;
+ QAction *autoRefreshAct;
+ QAction *fallbacksAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/settingseditor.pro b/examples/tools/settingseditor/settingseditor.pro
new file mode 100644
index 0000000000..79296b80a0
--- /dev/null
+++ b/examples/tools/settingseditor/settingseditor.pro
@@ -0,0 +1,17 @@
+HEADERS = locationdialog.h \
+ mainwindow.h \
+ settingstree.h \
+ variantdelegate.h
+SOURCES = locationdialog.cpp \
+ main.cpp \
+ mainwindow.cpp \
+ settingstree.cpp \
+ variantdelegate.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/settingseditor
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS settingseditor.pro inifiles
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/settingseditor
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/settingseditor/settingstree.cpp b/examples/tools/settingseditor/settingstree.cpp
new file mode 100644
index 0000000000..1fd80d756b
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "settingstree.h"
+#include "variantdelegate.h"
+
+SettingsTree::SettingsTree(QWidget *parent)
+ : QTreeWidget(parent)
+{
+ setItemDelegate(new VariantDelegate(this));
+
+ QStringList labels;
+ labels << tr("Setting") << tr("Type") << tr("Value");
+ setHeaderLabels(labels);
+ header()->setResizeMode(0, QHeaderView::Stretch);
+ header()->setResizeMode(2, QHeaderView::Stretch);
+
+ settings = 0;
+ refreshTimer.setInterval(2000);
+ autoRefresh = false;
+
+ groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ groupIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ keyIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
+
+ connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(maybeRefresh()));
+}
+
+void SettingsTree::setSettingsObject(QSettings *settings)
+{
+ delete this->settings;
+ this->settings = settings;
+ clear();
+
+ if (settings) {
+ settings->setParent(this);
+ refresh();
+ if (autoRefresh)
+ refreshTimer.start();
+ } else {
+ refreshTimer.stop();
+ }
+}
+
+QSize SettingsTree::sizeHint() const
+{
+ return QSize(800, 600);
+}
+
+void SettingsTree::setAutoRefresh(bool autoRefresh)
+{
+ this->autoRefresh = autoRefresh;
+ if (settings) {
+ if (autoRefresh) {
+ maybeRefresh();
+ refreshTimer.start();
+ } else {
+ refreshTimer.stop();
+ }
+ }
+}
+
+void SettingsTree::setFallbacksEnabled(bool enabled)
+{
+ if (settings) {
+ settings->setFallbacksEnabled(enabled);
+ refresh();
+ }
+}
+
+void SettingsTree::maybeRefresh()
+{
+ if (state() != EditingState)
+ refresh();
+}
+
+void SettingsTree::refresh()
+{
+ if (!settings)
+ return;
+
+ disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateSetting(QTreeWidgetItem*)));
+
+ settings->sync();
+ updateChildItems(0);
+
+ connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateSetting(QTreeWidgetItem*)));
+}
+
+bool SettingsTree::event(QEvent *event)
+{
+ if (event->type() == QEvent::WindowActivate) {
+ if (isActiveWindow() && autoRefresh)
+ maybeRefresh();
+ }
+ return QTreeWidget::event(event);
+}
+
+void SettingsTree::updateSetting(QTreeWidgetItem *item)
+{
+ QString key = item->text(0);
+ QTreeWidgetItem *ancestor = item->parent();
+ while (ancestor) {
+ key.prepend(ancestor->text(0) + "/");
+ ancestor = ancestor->parent();
+ }
+
+ settings->setValue(key, item->data(2, Qt::UserRole));
+ if (autoRefresh)
+ refresh();
+}
+
+void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
+{
+ int dividerIndex = 0;
+
+ foreach (QString group, settings->childGroups()) {
+ QTreeWidgetItem *child;
+ int childIndex = findChild(parent, group, dividerIndex);
+ if (childIndex != -1) {
+ child = childAt(parent, childIndex);
+ child->setText(1, "");
+ child->setText(2, "");
+ child->setData(2, Qt::UserRole, QVariant());
+ moveItemForward(parent, childIndex, dividerIndex);
+ } else {
+ child = createItem(group, parent, dividerIndex);
+ }
+ child->setIcon(0, groupIcon);
+ ++dividerIndex;
+
+ settings->beginGroup(group);
+ updateChildItems(child);
+ settings->endGroup();
+ }
+
+ foreach (QString key, settings->childKeys()) {
+ QTreeWidgetItem *child;
+ int childIndex = findChild(parent, key, 0);
+
+ if (childIndex == -1 || childIndex >= dividerIndex) {
+ if (childIndex != -1) {
+ child = childAt(parent, childIndex);
+ for (int i = 0; i < child->childCount(); ++i)
+ delete childAt(child, i);
+ moveItemForward(parent, childIndex, dividerIndex);
+ } else {
+ child = createItem(key, parent, dividerIndex);
+ }
+ child->setIcon(0, keyIcon);
+ ++dividerIndex;
+ } else {
+ child = childAt(parent, childIndex);
+ }
+
+ QVariant value = settings->value(key);
+ if (value.type() == QVariant::Invalid) {
+ child->setText(1, "Invalid");
+ } else {
+ child->setText(1, value.typeName());
+ }
+ child->setText(2, VariantDelegate::displayText(value));
+ child->setData(2, Qt::UserRole, value);
+ }
+
+ while (dividerIndex < childCount(parent))
+ delete childAt(parent, dividerIndex);
+}
+
+QTreeWidgetItem *SettingsTree::createItem(const QString &text,
+ QTreeWidgetItem *parent, int index)
+{
+ QTreeWidgetItem *after = 0;
+ if (index != 0)
+ after = childAt(parent, index - 1);
+
+ QTreeWidgetItem *item;
+ if (parent)
+ item = new QTreeWidgetItem(parent, after);
+ else
+ item = new QTreeWidgetItem(this, after);
+
+ item->setText(0, text);
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ return item;
+}
+
+QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index)
+{
+ if (parent)
+ return parent->child(index);
+ else
+ return topLevelItem(index);
+}
+
+int SettingsTree::childCount(QTreeWidgetItem *parent)
+{
+ if (parent)
+ return parent->childCount();
+ else
+ return topLevelItemCount();
+}
+
+int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
+ int startIndex)
+{
+ for (int i = startIndex; i < childCount(parent); ++i) {
+ if (childAt(parent, i)->text(0) == text)
+ return i;
+ }
+ return -1;
+}
+
+void SettingsTree::moveItemForward(QTreeWidgetItem *parent, int oldIndex,
+ int newIndex)
+{
+ for (int i = 0; i < oldIndex - newIndex; ++i)
+ delete childAt(parent, newIndex);
+}
diff --git a/examples/tools/settingseditor/settingstree.h b/examples/tools/settingseditor/settingstree.h
new file mode 100644
index 0000000000..63deb2a294
--- /dev/null
+++ b/examples/tools/settingseditor/settingstree.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SETTINGSTREE_H
+#define SETTINGSTREE_H
+
+#include <QIcon>
+#include <QTimer>
+#include <QTreeWidget>
+
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
+
+class SettingsTree : public QTreeWidget
+{
+ Q_OBJECT
+
+public:
+ SettingsTree(QWidget *parent = 0);
+
+ void setSettingsObject(QSettings *settings);
+ QSize sizeHint() const;
+
+public slots:
+ void setAutoRefresh(bool autoRefresh);
+ void setFallbacksEnabled(bool enabled);
+ void maybeRefresh();
+ void refresh();
+
+protected:
+ bool event(QEvent *event);
+
+private slots:
+ void updateSetting(QTreeWidgetItem *item);
+
+private:
+ void updateChildItems(QTreeWidgetItem *parent);
+ QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
+ int index);
+ QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index);
+ int childCount(QTreeWidgetItem *parent);
+ int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex);
+ void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
+
+ QSettings *settings;
+ QTimer refreshTimer;
+ bool autoRefresh;
+ QIcon groupIcon;
+ QIcon keyIcon;
+};
+
+#endif
diff --git a/examples/tools/settingseditor/variantdelegate.cpp b/examples/tools/settingseditor/variantdelegate.cpp
new file mode 100644
index 0000000000..5827b8447f
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "variantdelegate.h"
+
+VariantDelegate::VariantDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+ boolExp.setPattern("true|false");
+ boolExp.setCaseSensitivity(Qt::CaseInsensitive);
+
+ byteArrayExp.setPattern("[\\x00-\\xff]*");
+ charExp.setPattern(".");
+ colorExp.setPattern("\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)");
+ doubleExp.setPattern("");
+ pointExp.setPattern("\\((-?[0-9]*),(-?[0-9]*)\\)");
+ rectExp.setPattern("\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)");
+ signedIntegerExp.setPattern("-?[0-9]*");
+ sizeExp = pointExp;
+ unsignedIntegerExp.setPattern("[0-9]*");
+
+ dateExp.setPattern("([0-9]{,4})-([0-9]{,2})-([0-9]{,2})");
+ timeExp.setPattern("([0-9]{,2}):([0-9]{,2}):([0-9]{,2})");
+ dateTimeExp.setPattern(dateExp.pattern() + "T" + timeExp.pattern());
+}
+
+void VariantDelegate::paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ if (index.column() == 2) {
+ QVariant value = index.model()->data(index, Qt::UserRole);
+ if (!isSupportedType(value.type())) {
+ QStyleOptionViewItem myOption = option;
+ myOption.state &= ~QStyle::State_Enabled;
+ QItemDelegate::paint(painter, myOption, index);
+ return;
+ }
+ }
+
+ QItemDelegate::paint(painter, option, index);
+}
+
+QWidget *VariantDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem & /* option */,
+ const QModelIndex &index) const
+{
+ if (index.column() != 2)
+ return 0;
+
+ QVariant originalValue = index.model()->data(index, Qt::UserRole);
+ if (!isSupportedType(originalValue.type()))
+ return 0;
+
+ QLineEdit *lineEdit = new QLineEdit(parent);
+ lineEdit->setFrame(false);
+
+ QRegExp regExp;
+
+ switch (originalValue.type()) {
+ case QVariant::Bool:
+ regExp = boolExp;
+ break;
+ case QVariant::ByteArray:
+ regExp = byteArrayExp;
+ break;
+ case QVariant::Char:
+ regExp = charExp;
+ break;
+ case QVariant::Color:
+ regExp = colorExp;
+ break;
+ case QVariant::Date:
+ regExp = dateExp;
+ break;
+ case QVariant::DateTime:
+ regExp = dateTimeExp;
+ break;
+ case QVariant::Double:
+ regExp = doubleExp;
+ break;
+ case QVariant::Int:
+ case QVariant::LongLong:
+ regExp = signedIntegerExp;
+ break;
+ case QVariant::Point:
+ regExp = pointExp;
+ break;
+ case QVariant::Rect:
+ regExp = rectExp;
+ break;
+ case QVariant::Size:
+ regExp = sizeExp;
+ break;
+ case QVariant::Time:
+ regExp = timeExp;
+ break;
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ regExp = unsignedIntegerExp;
+ break;
+ default:
+ ;
+ }
+
+ if (!regExp.isEmpty()) {
+ QValidator *validator = new QRegExpValidator(regExp, lineEdit);
+ lineEdit->setValidator(validator);
+ }
+
+ return lineEdit;
+}
+
+void VariantDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QVariant value = index.model()->data(index, Qt::UserRole);
+ if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor))
+ lineEdit->setText(displayText(value));
+}
+
+void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
+ if (!lineEdit->isModified())
+ return;
+
+ QString text = lineEdit->text();
+ const QValidator *validator = lineEdit->validator();
+ if (validator) {
+ int pos;
+ if (validator->validate(text, pos) != QValidator::Acceptable)
+ return;
+ }
+
+ QVariant originalValue = index.model()->data(index, Qt::UserRole);
+ QVariant value;
+
+ switch (originalValue.type()) {
+ case QVariant::Char:
+ value = text.at(0);
+ break;
+ case QVariant::Color:
+ colorExp.exactMatch(text);
+ value = QColor(qMin(colorExp.cap(1).toInt(), 255),
+ qMin(colorExp.cap(2).toInt(), 255),
+ qMin(colorExp.cap(3).toInt(), 255),
+ qMin(colorExp.cap(4).toInt(), 255));
+ break;
+ case QVariant::Date:
+ {
+ QDate date = QDate::fromString(text, Qt::ISODate);
+ if (!date.isValid())
+ return;
+ value = date;
+ }
+ break;
+ case QVariant::DateTime:
+ {
+ QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate);
+ if (!dateTime.isValid())
+ return;
+ value = dateTime;
+ }
+ break;
+ case QVariant::Point:
+ pointExp.exactMatch(text);
+ value = QPoint(pointExp.cap(1).toInt(), pointExp.cap(2).toInt());
+ break;
+ case QVariant::Rect:
+ rectExp.exactMatch(text);
+ value = QRect(rectExp.cap(1).toInt(), rectExp.cap(2).toInt(),
+ rectExp.cap(3).toInt(), rectExp.cap(4).toInt());
+ break;
+ case QVariant::Size:
+ sizeExp.exactMatch(text);
+ value = QSize(sizeExp.cap(1).toInt(), sizeExp.cap(2).toInt());
+ break;
+ case QVariant::StringList:
+ value = text.split(",");
+ break;
+ case QVariant::Time:
+ {
+ QTime time = QTime::fromString(text, Qt::ISODate);
+ if (!time.isValid())
+ return;
+ value = time;
+ }
+ break;
+ default:
+ value = text;
+ value.convert(originalValue.type());
+ }
+
+ model->setData(index, displayText(value), Qt::DisplayRole);
+ model->setData(index, value, Qt::UserRole);
+}
+
+bool VariantDelegate::isSupportedType(QVariant::Type type)
+{
+ switch (type) {
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Char:
+ case QVariant::Color:
+ case QVariant::Date:
+ case QVariant::DateTime:
+ case QVariant::Double:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::Point:
+ case QVariant::Rect:
+ case QVariant::Size:
+ case QVariant::String:
+ case QVariant::StringList:
+ case QVariant::Time:
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ return true;
+ default:
+ return false;
+ }
+}
+
+QString VariantDelegate::displayText(const QVariant &value)
+{
+ switch (value.type()) {
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Char:
+ case QVariant::Double:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::String:
+ case QVariant::UInt:
+ case QVariant::ULongLong:
+ return value.toString();
+ case QVariant::Color:
+ {
+ QColor color = qvariant_cast<QColor>(value);
+ return QString("(%1,%2,%3,%4)")
+ .arg(color.red()).arg(color.green())
+ .arg(color.blue()).arg(color.alpha());
+ }
+ case QVariant::Date:
+ return value.toDate().toString(Qt::ISODate);
+ case QVariant::DateTime:
+ return value.toDateTime().toString(Qt::ISODate);
+ case QVariant::Invalid:
+ return "<Invalid>";
+ case QVariant::Point:
+ {
+ QPoint point = value.toPoint();
+ return QString("(%1,%2)").arg(point.x()).arg(point.y());
+ }
+ case QVariant::Rect:
+ {
+ QRect rect = value.toRect();
+ return QString("(%1,%2,%3,%4)")
+ .arg(rect.x()).arg(rect.y())
+ .arg(rect.width()).arg(rect.height());
+ }
+ case QVariant::Size:
+ {
+ QSize size = value.toSize();
+ return QString("(%1,%2)").arg(size.width()).arg(size.height());
+ }
+ case QVariant::StringList:
+ return value.toStringList().join(",");
+ case QVariant::Time:
+ return value.toTime().toString(Qt::ISODate);
+ default:
+ break;
+ }
+ return QString("<%1>").arg(value.typeName());
+}
diff --git a/examples/tools/settingseditor/variantdelegate.h b/examples/tools/settingseditor/variantdelegate.h
new file mode 100644
index 0000000000..abd4d93b8f
--- /dev/null
+++ b/examples/tools/settingseditor/variantdelegate.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VARIANTDELEGATE_H
+#define VARIANTDELEGATE_H
+
+#include <QItemDelegate>
+#include <QRegExp>
+
+class VariantDelegate : public QItemDelegate
+{
+ Q_OBJECT
+
+public:
+ VariantDelegate(QObject *parent = 0);
+
+ void paint(QPainter *painter, 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;
+
+ static bool isSupportedType(QVariant::Type type);
+ static QString displayText(const QVariant &value);
+
+private:
+ mutable QRegExp boolExp;
+ mutable QRegExp byteArrayExp;
+ mutable QRegExp charExp;
+ mutable QRegExp colorExp;
+ mutable QRegExp dateExp;
+ mutable QRegExp dateTimeExp;
+ mutable QRegExp doubleExp;
+ mutable QRegExp pointExp;
+ mutable QRegExp rectExp;
+ mutable QRegExp signedIntegerExp;
+ mutable QRegExp sizeExp;
+ mutable QRegExp timeExp;
+ mutable QRegExp unsignedIntegerExp;
+};
+
+#endif
diff --git a/examples/tools/styleplugin/plugin/plugin.pro b/examples/tools/styleplugin/plugin/plugin.pro
new file mode 100644
index 0000000000..442cc8ac8b
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/plugin.pro
@@ -0,0 +1,25 @@
+#! [0]
+TEMPLATE = lib
+CONFIG += plugin
+HEADERS = simplestyle.h \
+ simplestyleplugin.h
+SOURCES = simplestyle.cpp \
+ simplestyleplugin.cpp
+TARGET = simplestyleplugin
+#! [0]
+win32 {
+ CONFIG(debug, release|debug):DESTDIR = ../debug/styles/
+ CONFIG(release, release|debug):DESTDIR = ../release/styles/
+} else {
+ DESTDIR = ../styles/
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin/styles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS plugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin/plugin
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+symbian:TARGET.EPOCALLOWDLLDATA = 1
diff --git a/examples/tools/styleplugin/plugin/simplestyle.cpp b/examples/tools/styleplugin/plugin/simplestyle.cpp
new file mode 100644
index 0000000000..ea672166e2
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+
+#include "simplestyle.h"
+
+void SimpleStyle::polish(QPalette &palette)
+{
+ palette.setBrush(QPalette::Button, Qt::red);
+}
diff --git a/examples/tools/styleplugin/plugin/simplestyle.h b/examples/tools/styleplugin/plugin/simplestyle.h
new file mode 100644
index 0000000000..1d4d9d84ae
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyle.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIMPLESTYLE_H
+#define SIMPLESTYLE_H
+
+#include <QWindowsStyle>
+
+QT_BEGIN_NAMESPACE
+class QPalette;
+QT_END_NAMESPACE
+
+class SimpleStyle : public QWindowsStyle
+{
+ Q_OBJECT
+
+public:
+ SimpleStyle() {};
+
+ void polish(QPalette &palette);
+};
+
+#endif
diff --git a/examples/tools/styleplugin/plugin/simplestyleplugin.cpp b/examples/tools/styleplugin/plugin/simplestyleplugin.cpp
new file mode 100644
index 0000000000..28dbe5c857
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "simplestyleplugin.h"
+#include "simplestyle.h"
+
+//! [0]
+QStringList SimpleStylePlugin::keys() const
+{
+ return QStringList() << "SimpleStyle";
+}
+//! [0]
+
+//! [1]
+QStyle *SimpleStylePlugin::create(const QString &key)
+{
+ if (key.toLower() == "simplestyle")
+ return new SimpleStyle;
+ return 0;
+}
+//! [1]
+
+QT_BEGIN_NAMESPACE
+Q_EXPORT_PLUGIN2(simplestyleplugin, SimpleStylePlugin)
+QT_END_NAMESPACE
diff --git a/examples/tools/styleplugin/plugin/simplestyleplugin.h b/examples/tools/styleplugin/plugin/simplestyleplugin.h
new file mode 100644
index 0000000000..8a26cf6012
--- /dev/null
+++ b/examples/tools/styleplugin/plugin/simplestyleplugin.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SIMPLESTYLEPLUGIN_H
+#define SIMPLESTYLEPLUGIN_H
+
+#include <QStylePlugin>
+
+QT_BEGIN_NAMESPACE
+class QStringList;
+class QStyle;
+QT_END_NAMESPACE
+
+//! [0]
+class SimpleStylePlugin : public QStylePlugin
+{
+ Q_OBJECT
+
+public:
+ SimpleStylePlugin() {};
+
+ QStringList keys() const;
+ QStyle *create(const QString &key);
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/styleplugin/styleplugin.pro b/examples/tools/styleplugin/styleplugin.pro
new file mode 100644
index 0000000000..c7669aacab
--- /dev/null
+++ b/examples/tools/styleplugin/styleplugin.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = stylewindow \
+ plugin
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styleplugin.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/styleplugin/stylewindow/main.cpp b/examples/tools/styleplugin/stylewindow/main.cpp
new file mode 100644
index 0000000000..1cf42aa86d
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stylewindow.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ QApplication app(argv, args);
+ QApplication::setStyle(QStyleFactory::create("simplestyle"));
+
+ StyleWindow window;
+ window.resize(200, 50);
+ window.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/tools/styleplugin/stylewindow/stylewindow.cpp
new file mode 100644
index 0000000000..eb2e3c3007
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stylewindow.h"
+
+StyleWindow::StyleWindow()
+{
+ QPushButton *styledButton = new QPushButton(tr("Big Red Button"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(styledButton);
+
+ QGroupBox *styleBox = new QGroupBox(tr("A simple style button"));
+ styleBox->setLayout(layout);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(styleBox, 0, 0);
+ setLayout(outerLayout);
+
+ setWindowTitle(tr("Style Plugin Example"));
+}
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.h b/examples/tools/styleplugin/stylewindow/stylewindow.h
new file mode 100644
index 0000000000..aed21c77cc
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STYLEWINDOW_H
+#define STYLEWINDOW_H
+
+#include <QWidget>
+
+class StyleWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ StyleWindow();
+};
+
+#endif
diff --git a/examples/tools/styleplugin/stylewindow/stylewindow.pro b/examples/tools/styleplugin/stylewindow/stylewindow.pro
new file mode 100644
index 0000000000..bfa26ef3a1
--- /dev/null
+++ b/examples/tools/styleplugin/stylewindow/stylewindow.pro
@@ -0,0 +1,19 @@
+HEADERS = stylewindow.h
+SOURCES = stylewindow.cpp \
+ main.cpp
+
+TARGET = styleplugin
+win32 {
+ debug:DESTDIR = ../debug/
+ release:DESTDIR = ../release/
+} else {
+ DESTDIR = ../
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS stylewindow.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/styleplugin/stylewindow
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/tools.pro b/examples/tools/tools.pro
new file mode 100644
index 0000000000..1c7f6eb0d8
--- /dev/null
+++ b/examples/tools/tools.pro
@@ -0,0 +1,26 @@
+TEMPLATE = subdirs
+CONFIG += ordered
+SUBDIRS = codecs \
+ completer \
+ customcompleter \
+ echoplugin \
+ i18n \
+ inputpanel \
+ contiguouscache \
+ plugandpaintplugins \
+ plugandpaint \
+ regexp \
+ settingseditor \
+ styleplugin \
+ treemodelcompleter \
+ undoframework
+
+plugandpaint.depends = plugandpaintplugins
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tools.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/treemodelcompleter/main.cpp b/examples/tools/treemodelcompleter/main.cpp
new file mode 100644
index 0000000000..6c53f171d6
--- /dev/null
+++ b/examples/tools/treemodelcompleter/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(treemodelcompleter);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/treemodelcompleter/mainwindow.cpp b/examples/tools/treemodelcompleter/mainwindow.cpp
new file mode 100644
index 0000000000..3f832fa6ec
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.cpp
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "treemodelcompleter.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent), completer(0), lineEdit(0)
+{
+ createMenu();
+
+ completer = new TreeModelCompleter(this);
+ completer->setModel(modelFromFile(":/resources/treemodel.txt"));
+ completer->setSeparator(QLatin1String("."));
+ QObject::connect(completer, SIGNAL(highlighted(QModelIndex)),
+ this, SLOT(highlight(QModelIndex)));
+
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *modelLabel = new QLabel;
+ modelLabel->setText(tr("Tree Model<br>(Double click items to edit)"));
+
+ QLabel *modeLabel = new QLabel;
+ modeLabel->setText(tr("Completion Mode"));
+ modeCombo = new QComboBox;
+ modeCombo->addItem(tr("Inline"));
+ modeCombo->addItem(tr("Filtered Popup"));
+ modeCombo->addItem(tr("Unfiltered Popup"));
+ modeCombo->setCurrentIndex(1);
+
+ QLabel *caseLabel = new QLabel;
+ caseLabel->setText(tr("Case Sensitivity"));
+ caseCombo = new QComboBox;
+ caseCombo->addItem(tr("Case Insensitive"));
+ caseCombo->addItem(tr("Case Sensitive"));
+ caseCombo->setCurrentIndex(0);
+//! [0]
+
+//! [1]
+ QLabel *separatorLabel = new QLabel;
+ separatorLabel->setText(tr("Tree Separator"));
+
+ QLineEdit *separatorLineEdit = new QLineEdit;
+ separatorLineEdit->setText(completer->separator());
+ connect(separatorLineEdit, SIGNAL(textChanged(QString)),
+ completer, SLOT(setSeparator(QString)));
+
+ QCheckBox *wrapCheckBox = new QCheckBox;
+ wrapCheckBox->setText(tr("Wrap around completions"));
+ wrapCheckBox->setChecked(completer->wrapAround());
+ connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool)));
+
+ contentsLabel = new QLabel;
+ contentsLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ connect(separatorLineEdit, SIGNAL(textChanged(QString)),
+ this, SLOT(updateContentsLabel(QString)));
+
+ treeView = new QTreeView;
+ treeView->setModel(completer->model());
+ treeView->header()->hide();
+ treeView->expandAll();
+//! [1]
+
+//! [2]
+ connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int)));
+ connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int)));
+
+ lineEdit = new QLineEdit;
+ lineEdit->setCompleter(completer);
+//! [2]
+
+//! [3]
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(modelLabel, 0, 0); layout->addWidget(treeView, 0, 1);
+ layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1);
+ layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1);
+ layout->addWidget(separatorLabel, 3, 0); layout->addWidget(separatorLineEdit, 3, 1);
+ layout->addWidget(wrapCheckBox, 4, 0);
+ layout->addWidget(contentsLabel, 5, 0, 1, 2);
+ layout->addWidget(lineEdit, 6, 0, 1, 2);
+ centralWidget->setLayout(layout);
+ setCentralWidget(centralWidget);
+
+ changeCase(caseCombo->currentIndex());
+ changeMode(modeCombo->currentIndex());
+
+ setWindowTitle(tr("Tree Model Completer"));
+ lineEdit->setFocus();
+}
+//! [3]
+
+//! [4]
+void MainWindow::createMenu()
+{
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ QAction *aboutAct = new QAction(tr("About"), this);
+ QAction *aboutQtAct = new QAction(tr("About Qt"), this);
+
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(exitAction);
+
+ QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [4]
+
+//! [5]
+void MainWindow::changeMode(int index)
+{
+ QCompleter::CompletionMode mode;
+ if (index == 0)
+ mode = QCompleter::InlineCompletion;
+ else if (index == 1)
+ mode = QCompleter::PopupCompletion;
+ else
+ mode = QCompleter::UnfilteredPopupCompletion;
+
+ completer->setCompletionMode(mode);
+}
+//! [5]
+
+QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+{
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly))
+ return new QStringListModel(completer);
+
+#ifndef QT_NO_CURSOR
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+#endif
+ QStringList words;
+
+ QStandardItemModel *model = new QStandardItemModel(completer);
+ QVector<QStandardItem *> parents(10);
+ parents[0] = model->invisibleRootItem();
+
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ QString trimmedLine = line.trimmed();
+ if (line.isEmpty() || trimmedLine.isEmpty())
+ continue;
+
+ QRegExp re("^\\s+");
+ int nonws = re.indexIn(line);
+ int level = 0;
+ if (nonws == -1) {
+ level = 0;
+ } else {
+ if (line.startsWith("\t")) {
+ level = re.cap(0).length();
+ } else {
+ level = re.cap(0).length()/4;
+ }
+ }
+
+ if (level+1 >= parents.size())
+ parents.resize(parents.size()*2);
+
+ QStandardItem *item = new QStandardItem;
+ item->setText(trimmedLine);
+ parents[level]->appendRow(item);
+ parents[level+1] = item;
+ }
+
+#ifndef QT_NO_CURSOR
+ QApplication::restoreOverrideCursor();
+#endif
+
+ return model;
+}
+
+void MainWindow::highlight(const QModelIndex &index)
+{
+ QAbstractItemModel *completionModel = completer->completionModel();
+ QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(completionModel);
+ if (!proxy)
+ return;
+ QModelIndex sourceIndex = proxy->mapToSource(index);
+ treeView->selectionModel()->select(sourceIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+ treeView->scrollTo(index);
+}
+
+//! [6]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates how "
+ "to use a QCompleter with a custom tree model."));
+}
+//! [6]
+
+//! [7]
+void MainWindow::changeCase(int cs)
+{
+ completer->setCaseSensitivity(cs ? Qt::CaseSensitive : Qt::CaseInsensitive);
+}
+//! [7]
+
+void MainWindow::updateContentsLabel(const QString& sep)
+{
+ contentsLabel->setText(tr("Type path from model above with items at each level separated by a '%1'").arg(sep));
+}
+
diff --git a/examples/tools/treemodelcompleter/mainwindow.h b/examples/tools/treemodelcompleter/mainwindow.h
new file mode 100644
index 0000000000..a6bbf472fb
--- /dev/null
+++ b/examples/tools/treemodelcompleter/mainwindow.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QModelIndex>
+
+class TreeModelCompleter;
+QT_BEGIN_NAMESPACE
+class QAbstractItemModel;
+class QComboBox;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QCheckBox;
+class QTreeView;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+private slots:
+ void about();
+ void changeCase(int);
+ void changeMode(int);
+ void highlight(const QModelIndex&);
+ void updateContentsLabel(const QString&);
+//! [0]
+
+//! [1]
+private:
+ void createMenu();
+ QAbstractItemModel *modelFromFile(const QString& fileName);
+
+ QTreeView *treeView;
+ QComboBox *caseCombo;
+ QComboBox *modeCombo;
+ QLabel *contentsLabel;
+ TreeModelCompleter *completer;
+ QLineEdit *lineEdit;
+};
+//! [1]
+
+#endif // MAINWINDOW_H
diff --git a/examples/tools/treemodelcompleter/resources/treemodel.txt b/examples/tools/treemodelcompleter/resources/treemodel.txt
new file mode 100644
index 0000000000..06c90077af
--- /dev/null
+++ b/examples/tools/treemodelcompleter/resources/treemodel.txt
@@ -0,0 +1,20 @@
+Parent1
+ Child1
+ GrandChild1
+ GrandChild2
+ GrandChild3
+ GrandGrandChild1
+ Child2
+ GrandChild1
+ GrandGrandChild1
+ GrandChild2
+ Child3
+
+Parent2
+ Child1
+ GrandChild1
+ Child2
+ Child3
+ GrandChild1
+ GrandChild2
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.cpp b/examples/tools/treemodelcompleter/treemodelcompleter.cpp
new file mode 100644
index 0000000000..bd4cd223db
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "treemodelcompleter.h"
+#include <QStringList>
+
+//! [0]
+TreeModelCompleter::TreeModelCompleter(QObject *parent)
+ : QCompleter(parent)
+{
+}
+//! [0]
+
+//! [1]
+TreeModelCompleter::TreeModelCompleter(QAbstractItemModel *model, QObject *parent)
+ : QCompleter(model, parent)
+{
+}
+//! [1]
+
+void TreeModelCompleter::setSeparator(const QString &separator)
+{
+ sep = separator;
+}
+
+//! [2]
+QString TreeModelCompleter::separator() const
+{
+ return sep;
+}
+//! [2]
+
+//! [3]
+QStringList TreeModelCompleter::splitPath(const QString &path) const
+{
+ if (sep.isNull()) {
+ return QCompleter::splitPath(path);
+ }
+
+ return path.split(sep);
+}
+//! [3]
+
+//! [4]
+QString TreeModelCompleter::pathFromIndex(const QModelIndex &index) const
+{
+ if (sep.isNull()) {
+ return QCompleter::pathFromIndex(index);
+ }
+
+ // navigate up and accumulate data
+ QStringList dataList;
+ for (QModelIndex i = index; i.isValid(); i = i.parent()) {
+ dataList.prepend(model()->data(i, completionRole()).toString());
+ }
+
+ return dataList.join(sep);
+}
+//! [4]
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.h b/examples/tools/treemodelcompleter/treemodelcompleter.h
new file mode 100644
index 0000000000..df79f8f700
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TREEMODELCOMPLETER_H
+#define TREEMODELCOMPLETER_H
+
+#include <QCompleter>
+
+//! [0]
+class TreeModelCompleter : public QCompleter
+{
+ Q_OBJECT
+ Q_PROPERTY(QString separator READ separator WRITE setSeparator)
+
+public:
+ TreeModelCompleter(QObject *parent = 0);
+ TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
+
+ QString separator() const;
+public slots:
+ void setSeparator(const QString &separator);
+
+protected:
+ QStringList splitPath(const QString &path) const;
+ QString pathFromIndex(const QModelIndex &index) const;
+
+private:
+ QString sep;
+};
+//! [0]
+
+#endif // TREEMODELCOMPLETER_H
+
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.pro b/examples/tools/treemodelcompleter/treemodelcompleter.pro
new file mode 100644
index 0000000000..aafd718201
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.pro
@@ -0,0 +1,14 @@
+HEADERS = treemodelcompleter.h \
+ mainwindow.h
+SOURCES = treemodelcompleter.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = treemodelcompleter.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/treemodelcompleter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS treemodelcompleter.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/treemodelcompleter
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/treemodelcompleter/treemodelcompleter.qrc b/examples/tools/treemodelcompleter/treemodelcompleter.qrc
new file mode 100644
index 0000000000..1130fcd641
--- /dev/null
+++ b/examples/tools/treemodelcompleter/treemodelcompleter.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>resources/treemodel.txt</file>
+</qresource>
+</RCC>
diff --git a/examples/tools/undoframework/commands.cpp b/examples/tools/undoframework/commands.cpp
new file mode 100644
index 0000000000..ff7b0b7f1d
--- /dev/null
+++ b/examples/tools/undoframework/commands.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "commands.h"
+#include "diagramitem.h"
+
+//! [0]
+MoveCommand::MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
+ QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ myDiagramItem = diagramItem;
+ newPos = diagramItem->pos();
+ myOldPos = oldPos;
+}
+//! [0]
+
+//! [1]
+bool MoveCommand::mergeWith(const QUndoCommand *command)
+{
+ const MoveCommand *moveCommand = static_cast<const MoveCommand *>(command);
+ DiagramItem *item = moveCommand->myDiagramItem;
+
+ if (myDiagramItem != item)
+ return false;
+
+ newPos = item->pos();
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+
+ return true;
+}
+//! [1]
+
+//! [2]
+void MoveCommand::undo()
+{
+ myDiagramItem->setPos(myOldPos);
+ myDiagramItem->scene()->update();
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+}
+//! [2]
+
+//! [3]
+void MoveCommand::redo()
+{
+ myDiagramItem->setPos(newPos);
+ setText(QObject::tr("Move %1")
+ .arg(createCommandString(myDiagramItem, newPos)));
+}
+//! [3]
+
+//! [4]
+DeleteCommand::DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ myGraphicsScene = scene;
+ QList<QGraphicsItem *> list = myGraphicsScene->selectedItems();
+ list.first()->setSelected(false);
+ myDiagramItem = static_cast<DiagramItem *>(list.first());
+ setText(QObject::tr("Delete %1")
+ .arg(createCommandString(myDiagramItem, myDiagramItem->pos())));
+}
+//! [4]
+
+//! [5]
+void DeleteCommand::undo()
+{
+ myGraphicsScene->addItem(myDiagramItem);
+ myGraphicsScene->update();
+}
+//! [5]
+
+//! [6]
+void DeleteCommand::redo()
+{
+ myGraphicsScene->removeItem(myDiagramItem);
+}
+//! [6]
+
+//! [7]
+AddCommand::AddCommand(DiagramItem::DiagramType addType,
+ QGraphicsScene *scene, QUndoCommand *parent)
+ : QUndoCommand(parent)
+{
+ static int itemCount = 0;
+
+ myGraphicsScene = scene;
+ myDiagramItem = new DiagramItem(addType);
+ initialPosition = QPointF((itemCount * 15) % int(scene->width()),
+ (itemCount * 15) % int(scene->height()));
+ scene->update();
+ ++itemCount;
+ setText(QObject::tr("Add %1")
+ .arg(createCommandString(myDiagramItem, initialPosition)));
+}
+//! [7]
+
+AddCommand::~AddCommand()
+{
+ if (!myDiagramItem->scene())
+ delete myDiagramItem;
+}
+
+//! [8]
+void AddCommand::undo()
+{
+ myGraphicsScene->removeItem(myDiagramItem);
+ myGraphicsScene->update();
+}
+//! [8]
+
+//! [9]
+void AddCommand::redo()
+{
+ myGraphicsScene->addItem(myDiagramItem);
+ myDiagramItem->setPos(initialPosition);
+ myGraphicsScene->clearSelection();
+ myGraphicsScene->update();
+}
+//! [9]
+
+QString createCommandString(DiagramItem *item, const QPointF &pos)
+{
+ return QObject::tr("%1 at (%2, %3)")
+ .arg(item->diagramType() == DiagramItem::Box ? "Box" : "Triangle")
+ .arg(pos.x()).arg(pos.y());
+}
diff --git a/examples/tools/undoframework/commands.h b/examples/tools/undoframework/commands.h
new file mode 100644
index 0000000000..a4e4ab9549
--- /dev/null
+++ b/examples/tools/undoframework/commands.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+#include <QUndoCommand>
+
+#include "diagramitem.h"
+
+//! [0]
+class MoveCommand : public QUndoCommand
+{
+public:
+ enum { Id = 1234 };
+
+ MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
+ QUndoCommand *parent = 0);
+
+ void undo();
+ void redo();
+ bool mergeWith(const QUndoCommand *command);
+ int id() const { return Id; }
+
+private:
+ DiagramItem *myDiagramItem;
+ QPointF myOldPos;
+ QPointF newPos;
+};
+//! [0]
+
+//! [1]
+class DeleteCommand : public QUndoCommand
+{
+public:
+ DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
+
+ void undo();
+ void redo();
+
+private:
+ DiagramItem *myDiagramItem;
+ QGraphicsScene *myGraphicsScene;
+};
+//! [1]
+
+//! [2]
+class AddCommand : public QUndoCommand
+{
+public:
+ AddCommand(DiagramItem::DiagramType addType, QGraphicsScene *graphicsScene,
+ QUndoCommand *parent = 0);
+ ~AddCommand();
+
+ void undo();
+ void redo();
+
+private:
+ DiagramItem *myDiagramItem;
+ QGraphicsScene *myGraphicsScene;
+ QPointF initialPosition;
+};
+//! [2]
+
+QString createCommandString(DiagramItem *item, const QPointF &point);
+
+#endif
diff --git a/examples/tools/undoframework/diagramitem.cpp b/examples/tools/undoframework/diagramitem.cpp
new file mode 100644
index 0000000000..3e896f3926
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+
+#include "diagramitem.h"
+
+DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item,
+ QGraphicsScene *scene)
+ : QGraphicsPolygonItem(item, scene)
+{
+ if (diagramType == Box) {
+ boxPolygon << QPointF(0, 0) << QPointF(0, 30) << QPointF(30, 30)
+ << QPointF(30, 0) << QPointF(0, 0);
+ setPolygon(boxPolygon);
+ } else {
+ trianglePolygon << QPointF(15, 0) << QPointF(30, 30) << QPointF(0, 30)
+ << QPointF(15, 0);
+ setPolygon(trianglePolygon);
+ }
+
+ QColor color(static_cast<int>(qrand()) % 256,
+ static_cast<int>(qrand()) % 256, static_cast<int>(qrand()) % 256);
+ QBrush brush(color);
+ setBrush(brush);
+ setFlag(QGraphicsItem::ItemIsSelectable);
+ setFlag(QGraphicsItem::ItemIsMovable);
+}
diff --git a/examples/tools/undoframework/diagramitem.h b/examples/tools/undoframework/diagramitem.h
new file mode 100644
index 0000000000..9ca3c0a399
--- /dev/null
+++ b/examples/tools/undoframework/diagramitem.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIAGRAMITEM_H
+#define DIAGRAMITEM_H
+
+#include <QGraphicsPolygonItem>
+
+QT_BEGIN_NAMESPACE
+class QGraphicsItem;
+class QGraphicsScene;
+class QGraphicsSceneMouseEvent;
+class QPointF;
+QT_END_NAMESPACE
+
+class DiagramItem : public QGraphicsPolygonItem
+{
+public:
+ enum { Type = UserType + 1 };
+ enum DiagramType { Box, Triangle };
+
+ DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0,
+ QGraphicsScene *scene = 0);
+
+ DiagramType diagramType() const {
+ return polygon() == boxPolygon ? Box : Triangle;
+ }
+ int type() const { return Type; }
+
+private:
+ QPolygonF boxPolygon;
+ QPolygonF trianglePolygon;
+};
+
+#endif
diff --git a/examples/tools/undoframework/diagramscene.cpp b/examples/tools/undoframework/diagramscene.cpp
new file mode 100644
index 0000000000..7ffd2db3ac
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "diagramscene.h"
+#include "diagramitem.h"
+
+DiagramScene::DiagramScene(QObject *parent)
+ : QGraphicsScene(parent)
+{
+ movingItem = 0;
+}
+
+void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(),
+ event->buttonDownScenePos(Qt::LeftButton).y());
+ movingItem = itemAt(mousePos.x(), mousePos.y());
+
+ if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ oldPos = movingItem->pos();
+ }
+
+ clearSelection();
+ QGraphicsScene::mousePressEvent(event);
+}
+
+void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (oldPos != movingItem->pos())
+ emit itemMoved(qgraphicsitem_cast<DiagramItem *>(movingItem),
+ oldPos);
+ movingItem = 0;
+ }
+ QGraphicsScene::mouseReleaseEvent(event);
+}
diff --git a/examples/tools/undoframework/diagramscene.h b/examples/tools/undoframework/diagramscene.h
new file mode 100644
index 0000000000..6ee50fb337
--- /dev/null
+++ b/examples/tools/undoframework/diagramscene.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIAGRAMSCENE_H
+#define DIAGRAMSCENE_H
+
+#include <QObject>
+#include <QGraphicsScene>
+
+class DiagramItem;
+QT_BEGIN_NAMESPACE
+class QGraphicsSceneDragDropEvent;
+class QGraphicsViewItem;
+QT_END_NAMESPACE
+
+//! [0]
+class DiagramScene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ DiagramScene(QObject *parent = 0);
+
+signals:
+ void itemMoved(DiagramItem *movedItem, const QPointF &movedFromPosition);
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ QGraphicsItem *movingItem;
+ QPointF oldPos;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/undoframework/images/cross.png b/examples/tools/undoframework/images/cross.png
new file mode 100644
index 0000000000..09e5e8c2ad
--- /dev/null
+++ b/examples/tools/undoframework/images/cross.png
Binary files differ
diff --git a/examples/tools/undoframework/main.cpp b/examples/tools/undoframework/main.cpp
new file mode 100644
index 0000000000..abfa0aa462
--- /dev/null
+++ b/examples/tools/undoframework/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ Q_INIT_RESOURCE(undoframework);
+
+ QApplication app(argv, args);
+
+ MainWindow mainWindow;
+ mainWindow.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/tools/undoframework/mainwindow.cpp b/examples/tools/undoframework/mainwindow.cpp
new file mode 100644
index 0000000000..72c9cc14f4
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.cpp
@@ -0,0 +1,206 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "diagramscene.h"
+#include "diagramitem.h"
+#include "commands.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ undoStack = new QUndoStack(this);
+
+ createActions();
+ createMenus();
+
+ createUndoView();
+
+ diagramScene = new DiagramScene();
+ QBrush pixmapBrush(QPixmap(":/images/cross.png").scaled(30, 30));
+ diagramScene->setBackgroundBrush(pixmapBrush);
+ diagramScene->setSceneRect(QRect(0, 0, 500, 500));
+
+ connect(diagramScene, SIGNAL(itemMoved(DiagramItem*,QPointF)),
+ this, SLOT(itemMoved(DiagramItem*,QPointF)));
+
+ setWindowTitle("Undo Framework");
+ QGraphicsView *view = new QGraphicsView(diagramScene);
+ setCentralWidget(view);
+ resize(700, 500);
+}
+//! [0]
+
+//! [1]
+void MainWindow::createUndoView()
+{
+ undoView = new QUndoView(undoStack);
+ undoView->setWindowTitle(tr("Command List"));
+ undoView->show();
+ undoView->setAttribute(Qt::WA_QuitOnClose, false);
+}
+//! [1]
+
+//! [2]
+void MainWindow::createActions()
+{
+ deleteAction = new QAction(tr("&Delete Item"), this);
+ deleteAction->setShortcut(tr("Del"));
+ connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+//! [2] //! [3]
+
+//! [3] //! [4]
+ addBoxAction = new QAction(tr("Add &Box"), this);
+//! [4]
+ addBoxAction->setShortcut(tr("Ctrl+O"));
+ connect(addBoxAction, SIGNAL(triggered()), this, SLOT(addBox()));
+
+ addTriangleAction = new QAction(tr("Add &Triangle"), this);
+ addTriangleAction->setShortcut(tr("Ctrl+T"));
+ connect(addTriangleAction, SIGNAL(triggered()), this, SLOT(addTriangle()));
+
+//! [5]
+ undoAction = undoStack->createUndoAction(this, tr("&Undo"));
+ undoAction->setShortcuts(QKeySequence::Undo);
+
+ redoAction = undoStack->createRedoAction(this, tr("&Redo"));
+ redoAction->setShortcuts(QKeySequence::Redo);
+//! [5]
+
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcuts(QKeySequence::Quit);
+ connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAction = new QAction(tr("&About"), this);
+ QList<QKeySequence> aboutShortcuts;
+ aboutShortcuts << tr("Ctrl+A") << tr("Ctrl+B");
+ aboutAction->setShortcuts(aboutShortcuts);
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+}
+
+//! [6]
+void MainWindow::createMenus()
+{
+//! [6]
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(exitAction);
+
+//! [7]
+ editMenu = menuBar()->addMenu(tr("&Edit"));
+ editMenu->addAction(undoAction);
+ editMenu->addAction(redoAction);
+ editMenu->addSeparator();
+ editMenu->addAction(deleteAction);
+ connect(editMenu, SIGNAL(aboutToShow()),
+ this, SLOT(itemMenuAboutToShow()));
+ connect(editMenu, SIGNAL(aboutToHide()),
+ this, SLOT(itemMenuAboutToHide()));
+
+//! [7]
+ itemMenu = menuBar()->addMenu(tr("&Item"));
+ itemMenu->addAction(addBoxAction);
+ itemMenu->addAction(addTriangleAction);
+
+ helpMenu = menuBar()->addMenu(tr("&About"));
+ helpMenu->addAction(aboutAction);
+//! [8]
+}
+//! [8]
+
+//! [9]
+void MainWindow::itemMoved(DiagramItem *movedItem,
+ const QPointF &oldPosition)
+{
+ undoStack->push(new MoveCommand(movedItem, oldPosition));
+}
+//! [9]
+
+//! [10]
+void MainWindow::deleteItem()
+{
+ if (diagramScene->selectedItems().isEmpty())
+ return;
+
+ QUndoCommand *deleteCommand = new DeleteCommand(diagramScene);
+ undoStack->push(deleteCommand);
+}
+//! [10]
+
+//! [11]
+void MainWindow::itemMenuAboutToHide()
+{
+ deleteAction->setEnabled(true);
+}
+//! [11]
+
+//! [12]
+void MainWindow::itemMenuAboutToShow()
+{
+ deleteAction->setEnabled(!diagramScene->selectedItems().isEmpty());
+}
+//! [12]
+
+//! [13]
+void MainWindow::addBox()
+{
+ QUndoCommand *addCommand = new AddCommand(DiagramItem::Box, diagramScene);
+ undoStack->push(addCommand);
+}
+//! [13]
+
+//! [14]
+void MainWindow::addTriangle()
+{
+ QUndoCommand *addCommand = new AddCommand(DiagramItem::Triangle,
+ diagramScene);
+ undoStack->push(addCommand);
+}
+//! [14]
+
+//! [15]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Undo"),
+ tr("The <b>Undo</b> example demonstrates how to "
+ "use Qt's undo framework."));
+}
+//! [15]
diff --git a/examples/tools/undoframework/mainwindow.h b/examples/tools/undoframework/mainwindow.h
new file mode 100644
index 0000000000..c21ffa0a5e
--- /dev/null
+++ b/examples/tools/undoframework/mainwindow.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QToolBar;
+class QMenu;
+class QUndoStack;
+class QUndoView;
+QT_END_NAMESPACE
+class DiagramScene;
+class DiagramItem;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void itemMoved(DiagramItem *movedDiagram, const QPointF &moveStartPosition);
+
+private slots:
+ void deleteItem();
+ void addBox();
+ void addTriangle();
+ void about();
+ void itemMenuAboutToShow();
+ void itemMenuAboutToHide();
+
+private:
+ void createActions();
+ void createMenus();
+ void createUndoView();
+
+ QAction *deleteAction;
+ QAction *addBoxAction;
+ QAction *addTriangleAction;
+ QAction *undoAction;
+ QAction *redoAction;
+ QAction *exitAction;
+ QAction *aboutAction;
+
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *itemMenu;
+ QMenu *helpMenu;
+
+ DiagramScene *diagramScene;
+ QUndoStack *undoStack;
+ QUndoView *undoView;
+};
+//! [0]
+
+#endif
diff --git a/examples/tools/undoframework/undoframework.pro b/examples/tools/undoframework/undoframework.pro
new file mode 100644
index 0000000000..0f03091ce0
--- /dev/null
+++ b/examples/tools/undoframework/undoframework.pro
@@ -0,0 +1,18 @@
+HEADERS = commands.h \
+ diagramitem.h \
+ diagramscene.h \
+ mainwindow.h
+SOURCES = commands.cpp \
+ diagramitem.cpp \
+ diagramscene.cpp \
+ main.cpp \
+ mainwindow.cpp
+RESOURCES = undoframework.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/undoframework
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS undoframework.pro README images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tools/undoframework
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tools/undoframework/undoframework.qrc b/examples/tools/undoframework/undoframework.qrc
new file mode 100644
index 0000000000..6321d94d8d
--- /dev/null
+++ b/examples/tools/undoframework/undoframework.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/cross.png</file>
+ </qresource>
+ </RCC>
+
diff --git a/examples/touch/dials/dials.pro b/examples/touch/dials/dials.pro
new file mode 100644
index 0000000000..7f8ec9b616
--- /dev/null
+++ b/examples/touch/dials/dials.pro
@@ -0,0 +1,8 @@
+SOURCES += main.cpp
+FORMS += dials.ui
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/dials
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dials.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/dials
+INSTALLS += target sources
diff --git a/examples/touch/dials/dials.ui b/examples/touch/dials/dials.ui
new file mode 100644
index 0000000000..8ca7ae9475
--- /dev/null
+++ b/examples/touch/dials/dials.ui
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dials</class>
+ <widget class="QWidget" name="Dials">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QDial" name="dial_1">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDial" name="dial_2">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QDial" name="dial_3">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QDial" name="dial_4">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QDial" name="dial_5">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDial" name="dial_6">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QDial" name="dial_7">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QDial" name="dial_8">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/touch/dials/main.cpp b/examples/touch/dials/main.cpp
new file mode 100644
index 0000000000..f361984b31
--- /dev/null
+++ b/examples/touch/dials/main.cpp
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui 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 <QApplication>
+#include <QWidget>
+#include <QDial>
+
+#include "ui_dials.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QWidget window;
+ Ui::Dials dialsUi;
+ dialsUi.setupUi(&window);
+ QList<QAbstractSlider *> sliders = window.findChildren<QAbstractSlider *>();
+ foreach (QAbstractSlider *slider, sliders)
+ slider->setAttribute(Qt::WA_AcceptTouchEvents);
+ window.showMaximized();
+ return app.exec();
+}
diff --git a/examples/touch/fingerpaint/fingerpaint.pro b/examples/touch/fingerpaint/fingerpaint.pro
new file mode 100644
index 0000000000..21e4294cf8
--- /dev/null
+++ b/examples/touch/fingerpaint/fingerpaint.pro
@@ -0,0 +1,11 @@
+HEADERS = mainwindow.h \
+ scribblearea.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ scribblearea.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/fingerpaint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS fingerpaint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/fingerpaint
+INSTALLS += target sources
diff --git a/examples/touch/fingerpaint/main.cpp b/examples/touch/fingerpaint/main.cpp
new file mode 100644
index 0000000000..e50c13b230
--- /dev/null
+++ b/examples/touch/fingerpaint/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.showMaximized();
+ return app.exec();
+}
diff --git a/examples/touch/fingerpaint/mainwindow.cpp b/examples/touch/fingerpaint/mainwindow.cpp
new file mode 100644
index 0000000000..37b7ed73f4
--- /dev/null
+++ b/examples/touch/fingerpaint/mainwindow.cpp
@@ -0,0 +1,217 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "scribblearea.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ scribbleArea = new ScribbleArea;
+ setCentralWidget(scribbleArea);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Finger Paint"));
+ resize(500, 500);
+}
+//! [0]
+
+//! [1]
+void MainWindow::closeEvent(QCloseEvent *event)
+//! [1] //! [2]
+{
+ if (maybeSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+//! [2]
+
+//! [3]
+void MainWindow::open()
+//! [3] //! [4]
+{
+ if (maybeSave()) {
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"), QDir::currentPath());
+ if (!fileName.isEmpty())
+ scribbleArea->openImage(fileName);
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::save()
+//! [5] //! [6]
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ QByteArray fileFormat = action->data().toByteArray();
+ saveFile(fileFormat);
+}
+//! [6]
+
+//! [11]
+void MainWindow::about()
+//! [11] //! [12]
+{
+ QMessageBox::about(this, tr("About Scribble"),
+ tr("<p>The <b>Scribble</b> example shows how to use QMainWindow as the "
+ "base widget for an application, and how to reimplement some of "
+ "QWidget's event handlers to receive the events generated for "
+ "the application's widgets:</p><p> We reimplement the mouse event "
+ "handlers to facilitate 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.</p><p> The example also demonstrates "
+ "how to use QPainter to draw an image in real time, as well as "
+ "to repaint widgets.</p>"));
+}
+//! [12]
+
+//! [13]
+void MainWindow::createActions()
+//! [13] //! [14]
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
+ QString text = tr("%1...").arg(QString(format).toUpper());
+
+ QAction *action = new QAction(text, this);
+ action->setData(format);
+ connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ saveAsActs.append(action);
+ }
+
+ printAct = new QAction(tr("&Print..."), this);
+ connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ clearScreenAct = new QAction(tr("&Clear Screen"), this);
+ clearScreenAct->setShortcut(tr("Ctrl+L"));
+ connect(clearScreenAct, SIGNAL(triggered()),
+ scribbleArea, SLOT(clearImage()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+//! [14]
+
+//! [15]
+void MainWindow::createMenus()
+//! [15] //! [16]
+{
+ saveAsMenu = new QMenu(tr("&Save As"), this);
+ foreach (QAction *action, saveAsActs)
+ saveAsMenu->addAction(action);
+
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addMenu(saveAsMenu);
+ fileMenu->addAction(printAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ optionMenu = new QMenu(tr("&Options"), this);
+ optionMenu->addAction(clearScreenAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(optionMenu);
+ menuBar()->addMenu(helpMenu);
+}
+//! [16]
+
+//! [17]
+bool MainWindow::maybeSave()
+//! [17] //! [18]
+{
+ if (scribbleArea->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Scribble"),
+ tr("The image has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save) {
+ return saveFile("png");
+ } else if (ret == QMessageBox::Cancel) {
+ return false;
+ }
+ }
+ return true;
+}
+//! [18]
+
+//! [19]
+bool MainWindow::saveFile(const QByteArray &fileFormat)
+//! [19] //! [20]
+{
+ QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(QString(fileFormat.toUpper()))
+ .arg(QString(fileFormat)));
+ if (fileName.isEmpty()) {
+ return false;
+ } else {
+ return scribbleArea->saveImage(fileName, fileFormat);
+ }
+}
+//! [20]
diff --git a/examples/touch/fingerpaint/mainwindow.h b/examples/touch/fingerpaint/mainwindow.h
new file mode 100644
index 0000000000..cd08e223d7
--- /dev/null
+++ b/examples/touch/fingerpaint/mainwindow.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+class ScribbleArea;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void open();
+ void save();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ bool maybeSave();
+ bool saveFile(const QByteArray &fileFormat);
+
+ ScribbleArea *scribbleArea;
+
+ QMenu *saveAsMenu;
+ QMenu *fileMenu;
+ QMenu *optionMenu;
+ QMenu *helpMenu;
+
+ QAction *openAct;
+ QList<QAction *> saveAsActs;
+ QAction *exitAct;
+ QAction *printAct;
+ QAction *clearScreenAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/touch/fingerpaint/scribblearea.cpp b/examples/touch/fingerpaint/scribblearea.cpp
new file mode 100644
index 0000000000..f66e61cfd3
--- /dev/null
+++ b/examples/touch/fingerpaint/scribblearea.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "scribblearea.h"
+
+//! [0]
+ScribbleArea::ScribbleArea(QWidget *parent)
+ : QWidget(parent)
+{
+ setAttribute(Qt::WA_AcceptTouchEvents);
+ setAttribute(Qt::WA_StaticContents);
+ modified = false;
+
+ myPenColors
+ << QColor("green")
+ << QColor("purple")
+ << QColor("red")
+ << QColor("blue")
+ << QColor("yellow")
+
+ << QColor("pink")
+ << QColor("orange")
+ << QColor("brown")
+ << QColor("grey")
+ << QColor("black");
+}
+//! [0]
+
+//! [1]
+bool ScribbleArea::openImage(const QString &fileName)
+//! [1] //! [2]
+{
+ QImage loadedImage;
+ if (!loadedImage.load(fileName))
+ return false;
+
+ QSize newSize = loadedImage.size().expandedTo(size());
+ resizeImage(&loadedImage, newSize);
+ image = loadedImage;
+ modified = false;
+ update();
+ return true;
+}
+//! [2]
+
+//! [3]
+bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat)
+//! [3] //! [4]
+{
+ QImage visibleImage = image;
+ resizeImage(&visibleImage, size());
+
+ if (visibleImage.save(fileName, fileFormat)) {
+ modified = false;
+ return true;
+ } else {
+ return false;
+ }
+}
+//! [4]
+
+//! [9]
+void ScribbleArea::clearImage()
+//! [9] //! [10]
+{
+ image.fill(qRgb(255, 255, 255));
+ modified = true;
+ update();
+}
+//! [10]
+
+//! [12] //! [13]
+void ScribbleArea::paintEvent(QPaintEvent *event)
+//! [13] //! [14]
+{
+ QPainter painter(this);
+ const QRect rect = event->rect();
+ painter.drawImage(rect.topLeft(), image, rect);
+}
+//! [14]
+
+//! [15]
+void ScribbleArea::resizeEvent(QResizeEvent *event)
+//! [15] //! [16]
+{
+ if (width() > image.width() || height() > image.height()) {
+ int newWidth = qMax(width() + 128, image.width());
+ int newHeight = qMax(height() + 128, image.height());
+ resizeImage(&image, QSize(newWidth, newHeight));
+ update();
+ }
+ QWidget::resizeEvent(event);
+}
+//! [16]
+
+//! [19]
+void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
+//! [19] //! [20]
+{
+ if (image->size() == newSize)
+ return;
+
+ QImage newImage(newSize, QImage::Format_RGB32);
+ newImage.fill(qRgb(255, 255, 255));
+ QPainter painter(&newImage);
+ painter.drawImage(QPoint(0, 0), *image);
+ *image = newImage;
+}
+//! [20]
+
+//! [21]
+void ScribbleArea::print()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+
+ QPrintDialog *printDialog = new QPrintDialog(&printer, this);
+//! [21] //! [22]
+ if (printDialog->exec() == QDialog::Accepted) {
+ QPainter painter(&printer);
+ QRect rect = painter.viewport();
+ QSize size = image.size();
+ size.scale(rect.size(), Qt::KeepAspectRatio);
+ painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
+ painter.setWindow(image.rect());
+ painter.drawImage(0, 0, image);
+ }
+#endif // QT_NO_PRINTER
+}
+//! [22]
+
+bool ScribbleArea::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ {
+ QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ foreach (const QTouchEvent::TouchPoint &touchPoint, touchPoints) {
+ switch (touchPoint.state()) {
+ case Qt::TouchPointStationary:
+ // don't do anything if this touch point hasn't moved
+ continue;
+ default:
+ {
+ QRectF rect = touchPoint.rect();
+ if (rect.isEmpty()) {
+ qreal diameter = qreal(50) * touchPoint.pressure();
+ rect.setSize(QSizeF(diameter, diameter));
+ }
+
+ QPainter painter(&image);
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(myPenColors.at(touchPoint.id() % myPenColors.count()));
+ painter.drawEllipse(rect);
+ painter.end();
+
+ modified = true;
+ int rad = 2;
+ update(rect.toRect().adjusted(-rad,-rad, +rad, +rad));
+ }
+ break;
+ }
+ }
+ break;
+ }
+ default:
+ return QWidget::event(event);
+ }
+ return true;
+}
diff --git a/examples/touch/fingerpaint/scribblearea.h b/examples/touch/fingerpaint/scribblearea.h
new file mode 100644
index 0000000000..e698be4f2d
--- /dev/null
+++ b/examples/touch/fingerpaint/scribblearea.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIBBLEAREA_H
+#define SCRIBBLEAREA_H
+
+#include <QColor>
+#include <QImage>
+#include <QPoint>
+#include <QWidget>
+
+//! [0]
+class ScribbleArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ScribbleArea(QWidget *parent = 0);
+
+ bool openImage(const QString &fileName);
+ bool saveImage(const QString &fileName, const char *fileFormat);
+
+ bool isModified() const { return modified; }
+
+public slots:
+ void clearImage();
+ void print();
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ bool event(QEvent *event);
+
+private:
+ void resizeImage(QImage *image, const QSize &newSize);
+
+ bool modified;
+ QList<QColor> myPenColors;
+ QImage image;
+};
+//! [0]
+
+#endif
diff --git a/examples/touch/knobs/knob.cpp b/examples/touch/knobs/knob.cpp
new file mode 100644
index 0000000000..031c0e10da
--- /dev/null
+++ b/examples/touch/knobs/knob.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "knob.h"
+
+#include <QBrush>
+#include <QTouchEvent>
+
+Knob::Knob()
+ : QGraphicsEllipseItem(-50, -50, 100, 100)
+{
+ setAcceptTouchEvents(true);
+ setBrush(Qt::lightGray);
+
+ QGraphicsEllipseItem *leftItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
+ leftItem->setPos(-40, -10);
+ leftItem->setBrush(Qt::darkGreen);
+
+ QGraphicsEllipseItem *rightItem = new QGraphicsEllipseItem(0, 0, 20, 20, this);
+ rightItem->setPos(20, -10);
+ rightItem->setBrush(Qt::darkRed);
+}
+
+bool Knob::sceneEvent(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ {
+ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
+
+ if (touchEvent->touchPoints().count() == 2) {
+ const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
+ const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();
+
+ QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
+ QLineF line2(touchPoint1.scenePos(), touchPoint2.scenePos());
+
+ rotate(line2.angleTo(line1));
+ }
+
+ break;
+ }
+
+ default:
+ return QGraphicsItem::sceneEvent(event);
+ }
+
+ return true;
+}
diff --git a/examples/touch/knobs/knob.h b/examples/touch/knobs/knob.h
new file mode 100644
index 0000000000..863df532f5
--- /dev/null
+++ b/examples/touch/knobs/knob.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef KNOB_H
+#define KNOB_H
+
+#include <QGraphicsItem>
+
+class Knob : public QGraphicsEllipseItem
+{
+public:
+ Knob();
+
+ bool sceneEvent(QEvent *event);
+};
+
+#endif // KNOB_H
diff --git a/examples/touch/knobs/knobs.pro b/examples/touch/knobs/knobs.pro
new file mode 100644
index 0000000000..c1caa98dfd
--- /dev/null
+++ b/examples/touch/knobs/knobs.pro
@@ -0,0 +1,8 @@
+HEADERS = knob.h
+SOURCES = main.cpp knob.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/knobs
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS knobs.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/knobs
+INSTALLS += target sources
diff --git a/examples/touch/knobs/main.cpp b/examples/touch/knobs/main.cpp
new file mode 100644
index 0000000000..8ffa81944a
--- /dev/null
+++ b/examples/touch/knobs/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QGraphicsView>
+
+#include "knob.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+ Knob *knob1 = new Knob;
+ knob1->setPos(-110, 0);
+ Knob *knob2 = new Knob;
+
+ scene.addItem(knob1);
+ scene.addItem(knob2);
+
+ view.showMaximized();
+ view.fitInView(scene.sceneRect().adjusted(-20, -20, 20, 20), Qt::KeepAspectRatio);
+
+ return app.exec();
+}
diff --git a/examples/touch/pinchzoom/graphicsview.cpp b/examples/touch/pinchzoom/graphicsview.cpp
new file mode 100644
index 0000000000..8c30857b64
--- /dev/null
+++ b/examples/touch/pinchzoom/graphicsview.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphicsview.h"
+
+#include <QScrollBar>
+#include <QTouchEvent>
+
+GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent)
+ : QGraphicsView(scene, parent), totalScaleFactor(1)
+{
+ viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
+ setDragMode(ScrollHandDrag);
+}
+
+bool GraphicsView::viewportEvent(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ {
+ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
+ QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
+ if (touchPoints.count() == 2) {
+ // determine scale factor
+ const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
+ const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
+ qreal currentScaleFactor =
+ QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
+ / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();
+ if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
+ // if one of the fingers is released, remember the current scale
+ // factor so that adding another finger later will continue zooming
+ // by adding new scale factor to the existing remembered value.
+ totalScaleFactor *= currentScaleFactor;
+ currentScaleFactor = 1;
+ }
+ setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor,
+ totalScaleFactor * currentScaleFactor));
+ }
+ return true;
+ }
+ default:
+ break;
+ }
+ return QGraphicsView::viewportEvent(event);
+}
diff --git a/examples/touch/pinchzoom/graphicsview.h b/examples/touch/pinchzoom/graphicsview.h
new file mode 100644
index 0000000000..3f227f4fc6
--- /dev/null
+++ b/examples/touch/pinchzoom/graphicsview.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+#include <QGraphicsView>
+
+class GraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0);
+
+ bool viewportEvent(QEvent *event);
+
+private:
+ qreal totalScaleFactor;
+};
diff --git a/examples/touch/pinchzoom/images/cheese.jpg b/examples/touch/pinchzoom/images/cheese.jpg
new file mode 100644
index 0000000000..dea5795fd0
--- /dev/null
+++ b/examples/touch/pinchzoom/images/cheese.jpg
Binary files differ
diff --git a/examples/touch/pinchzoom/main.cpp b/examples/touch/pinchzoom/main.cpp
new file mode 100644
index 0000000000..defe0028af
--- /dev/null
+++ b/examples/touch/pinchzoom/main.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "graphicsview.h"
+#include "mouse.h"
+
+#include <QtGui>
+
+#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]
+ GraphicsView view(&scene);
+ view.setRenderHint(QPainter::Antialiasing);
+ view.setBackgroundBrush(QPixmap(":/images/cheese.jpg"));
+//! [4] //! [5]
+ view.setCacheMode(QGraphicsView::CacheBackground);
+ view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
+//! [5] //! [6]
+ view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
+ view.showMaximized();
+
+ return app.exec();
+}
+//! [6]
diff --git a/examples/touch/pinchzoom/mice.qrc b/examples/touch/pinchzoom/mice.qrc
new file mode 100644
index 0000000000..accdb4d0a6
--- /dev/null
+++ b/examples/touch/pinchzoom/mice.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>images/cheese.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/touch/pinchzoom/mouse.cpp b/examples/touch/pinchzoom/mouse.cpp
new file mode 100644
index 0000000000..74ff462f78
--- /dev/null
+++ b/examples/touch/pinchzoom/mouse.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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)
+{
+ rotate(qrand() % (360 * 16));
+ startTimer(1000 / 33);
+}
+//! [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::timerEvent(QTimerEvent *)
+{
+//! [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;
+
+ rotate(dx);
+ setPos(mapToParent(0, -(3 + sin(speed) * 3)));
+}
+//! [11]
diff --git a/examples/touch/pinchzoom/mouse.h b/examples/touch/pinchzoom/mouse.h
new file mode 100644
index 0000000000..3a392bdb6e
--- /dev/null
+++ b/examples/touch/pinchzoom/mouse.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOUSE_H
+#define MOUSE_H
+
+#include <QGraphicsObject>
+
+//! [0]
+class Mouse : public QGraphicsObject
+{
+ Q_OBJECT
+
+public:
+ Mouse();
+
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private:
+ qreal angle;
+ qreal speed;
+ qreal mouseEyeDirection;
+ QColor color;
+};
+//! [0]
+
+#endif
diff --git a/examples/touch/pinchzoom/pinchzoom.pro b/examples/touch/pinchzoom/pinchzoom.pro
new file mode 100644
index 0000000000..e6864237e3
--- /dev/null
+++ b/examples/touch/pinchzoom/pinchzoom.pro
@@ -0,0 +1,16 @@
+HEADERS += \
+ mouse.h \
+ graphicsview.h
+SOURCES += \
+ main.cpp \
+ mouse.cpp \
+ graphicsview.cpp
+
+RESOURCES += \
+ mice.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/pinchzoom
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS pinchzoom.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/touch/pinchzoom
+INSTALLS += target sources
diff --git a/examples/touch/touch.pro b/examples/touch/touch.pro
new file mode 100644
index 0000000000..d5983eb581
--- /dev/null
+++ b/examples/touch/touch.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS = pinchzoom fingerpaint knobs dials
diff --git a/examples/tutorials/README b/examples/tutorials/README
new file mode 100644
index 0000000000..0aab26348b
--- /dev/null
+++ b/examples/tutorials/README
@@ -0,0 +1,37 @@
+Qt is supplied with tutorials that have been written to provide developers
+with an introduction to the Qt API.
+
+The example and demo launcher can be used to explore these tutorials, lets
+you view the documentation in Qt Assistant, and is able to launch each part
+in a series of tutorial programs.
+
+Documentation for tutorials can be found in the Tutorial and Examples section
+of the Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/tutorials/addressbook-fr/README b/examples/tutorials/addressbook-fr/README
new file mode 100644
index 0000000000..359859390e
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/README
@@ -0,0 +1,42 @@
+The Address Book Tutorial shows how to put together a simple yet
+fully-functioning GUI application. The tutorial chapters can be found in the
+Qt documentation, which can be viewed using Qt Assistant or a Web browser.
+
+The tutorial is also available online at
+
+http://qt.nokia.com/doc/4.4/tutorial.html
+
+All programs corresponding to the chapters in the tutorial should
+automatically be built when Qt is compiled, or will be provided as
+pre-built executables if you have obtained a binary package of Qt.
+
+If you have only compiled the Qt libraries, use the following instructions
+to build the tutorial.
+
+On Linux/Unix:
+
+Typing 'make' in this directory builds all the programs (part1/part1,
+part2/part2, part3/part3 and so on). Typing 'make' in each subdirectory
+builds just that tutorial program.
+
+On Windows:
+
+Create a single Visual Studio project for the tutorial directory in
+the usual way. You can do this by typing the following at the command
+line:
+
+qmake -tp vc
+
+You should now be able to open the project file in Visual Studio and
+build all of the tutorial programs at the same time.
+
+On Mac OS X:
+
+Create an Xcode project with the .pro file in the tutorial directory.
+You can do this by typing the following at the command line:
+
+qmake -spec macx-xcode
+
+Then open the generated Xcode project in Xcode and build it.
+
+Feel free to send comments about the tutorial to qt-bugs@trolltech.com.
diff --git a/examples/tutorials/addressbook-fr/addressbook-fr.pro b/examples/tutorials/addressbook-fr/addressbook-fr.pro
new file mode 100644
index 0000000000..ba945e24d6
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/addressbook-fr.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+SUBDIRS = part1 part2 part3 part4 part5 part6 part7
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook-fr
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS addressbook-fr.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook-fr
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part1/addressbook.cpp b/examples/tutorials/addressbook-fr/part1/addressbook.cpp
new file mode 100644
index 0000000000..7ff4c9ea79
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/addressbook.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [constructor and input fields]
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+//! [constructor and input fields]
+
+//! [layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+//! [layout]
+
+//![setting the layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+//! [setting the layout]
diff --git a/examples/tutorials/addressbook-fr/part1/addressbook.h b/examples/tutorials/addressbook-fr/part1/addressbook.h
new file mode 100644
index 0000000000..90b9b0ed48
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/addressbook.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [class definition]
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+private:
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+};
+//! [class definition]
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part1/main.cpp b/examples/tutorials/addressbook-fr/part1/main.cpp
new file mode 100644
index 0000000000..970921d537
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tutorials/addressbook-fr/part1/part1.pro b/examples/tutorials/addressbook-fr/part1/part1.pro
new file mode 100644
index 0000000000..c22df740f4
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part1/part1.pro
@@ -0,0 +1,9 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part1
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part1.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part1
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part2/addressbook.cpp b/examples/tutorials/addressbook-fr/part2/addressbook.cpp
new file mode 100644
index 0000000000..36023c850a
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/addressbook.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+//! [setting readonly 1]
+ nameLine->setReadOnly(true);
+//! [setting readonly 1]
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+//! [setting readonly 2]
+ addressText->setReadOnly(true);
+//! [setting readonly 2]
+
+//! [pushbutton declaration]
+ addButton = new QPushButton(tr("&Add"));
+ addButton->show();
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+//! [pushbutton declaration]
+//! [connecting signals and slots]
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+//! [connecting signals and slots]
+//! [vertical layout]
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton, Qt::AlignTop);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+//! [vertical layout]
+//! [grid layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+//! [grid layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+//! [addContact]
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ submitButton->show();
+ cancelButton->show();
+}
+//! [addContact]
+
+//! [submitContact part1]
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if ( name.isEmpty()|| address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+//! [submitContact part1]
+//! [submitContact part2]
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ return;
+ }
+//! [submitContact part2]
+//! [submitContact part3]
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+ submitButton->hide();
+ cancelButton->hide();
+}
+//! [submitContact part3]
+//! [cancel]
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ nameLine->setReadOnly(true);
+
+ addressText->setText(oldAddress);
+ addressText->setReadOnly(true);
+
+ addButton->setEnabled(true);
+ submitButton->hide();
+ cancelButton->hide();
+}
+//! [cancel]
diff --git a/examples/tutorials/addressbook-fr/part2/addressbook.h b/examples/tutorials/addressbook-fr/part2/addressbook.h
new file mode 100644
index 0000000000..9f9b2b0b91
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/addressbook.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+//! [slots]
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [slots]
+
+//! [pushbutton declaration]
+private:
+ QPushButton *addButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+//! [pushbutton declaration]
+
+//! [remaining private variables]
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+};
+//! [remaining private variables]
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part2/main.cpp b/examples/tutorials/addressbook-fr/part2/main.cpp
new file mode 100644
index 0000000000..970921d537
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tutorials/addressbook-fr/part2/part2.pro b/examples/tutorials/addressbook-fr/part2/part2.pro
new file mode 100644
index 0000000000..a0a53e6e6c
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part2/part2.pro
@@ -0,0 +1,9 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part2
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part3/addressbook.cpp b/examples/tutorials/addressbook-fr/part3/addressbook.cpp
new file mode 100644
index 0000000000..47d312e7ac
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/addressbook.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+ addButton->show();
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+//! [navigation pushbuttons]
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+//! [navigation pushbuttons]
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+//! [connecting navigation signals]
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+//! [connecting navigation signals]
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton, Qt::AlignTop);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+//! [navigation layout]
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+//! [ navigation layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+//! [adding navigation layout]
+ mainLayout->addLayout(buttonLayout2, 3, 1);
+//! [adding navigation layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+//! [disabling navigation]
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+//! [disabling navigation]
+ submitButton->show();
+ cancelButton->show();
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+//! [enabling navigation]
+ int number = contacts.size();
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+//! [enabling navigation]
+ submitButton->hide();
+ cancelButton->hide();
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+}
+
+//! [next() function]
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [next() function]
+//! [previous() function]
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()){
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [previous() function]
diff --git a/examples/tutorials/addressbook-fr/part3/addressbook.h b/examples/tutorials/addressbook-fr/part3/addressbook.h
new file mode 100644
index 0000000000..192a5aef46
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/addressbook.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [navigation functions]
+ void next();
+ void previous();
+//! [navigation functions]
+
+private:
+ QPushButton *addButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+//! [navigation pushbuttons]
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+//! [navigation pushbuttons]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part3/main.cpp b/examples/tutorials/addressbook-fr/part3/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook-fr/part3/part3.pro b/examples/tutorials/addressbook-fr/part3/part3.pro
new file mode 100644
index 0000000000..0e28296c5d
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part3/part3.pro
@@ -0,0 +1,9 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part3
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part3.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part3
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part4/addressbook.cpp b/examples/tutorials/addressbook-fr/part4/addressbook.cpp
new file mode 100644
index 0000000000..e88ab6a8e2
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/addressbook.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+//! [edit and remove buttons]
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+//! [edit and remove buttons]
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+//! [connecting edit and remove]
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+//! [connecting edit and remove]
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+//! [adding edit and remove to the layout]
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+//! [adding edit and remove to the layout]
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 3, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+//! [editContact() function]
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+//! [editContact() function]
+//! [submitContact() function beginning]
+void AddressBook::submitContact()
+{
+//! [submitContact() function beginning]
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+//! [submitContact() function part1]
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+//! [submitContact() function part1]
+//! [submitContact() function part2]
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [submitContact() function part2]
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+//! [removeContact() function]
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [removeContact() function]
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [update interface() part 1]
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+ break;
+//! [update interface() part 1]
+//! [update interface() part 2]
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number >1 );
+
+ submitButton->hide();
+ cancelButton->hide();
+ break;
+ }
+}
+//! [update interface() part 2]
diff --git a/examples/tutorials/addressbook-fr/part4/addressbook.h b/examples/tutorials/addressbook-fr/part4/addressbook.h
new file mode 100644
index 0000000000..4d653d1fad
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/addressbook.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+//! [Mode enum]
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+//! [Mode enum]
+
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [edit and remove slots]
+ void editContact();
+ void removeContact();
+//! [edit and remove slots]
+ void next();
+ void previous();
+
+private:
+//! [updateInterface() declaration]
+ void updateInterface(Mode mode);
+//! [updateInterface() declaration]
+ QPushButton *addButton;
+//! [buttons declaration]
+ QPushButton *editButton;
+ QPushButton *removeButton;
+//! [buttons declaration]
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+//! [mode declaration]
+ Mode currentMode;
+//! [mode declaration]
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part4/main.cpp b/examples/tutorials/addressbook-fr/part4/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook-fr/part4/part4.pro b/examples/tutorials/addressbook-fr/part4/part4.pro
new file mode 100644
index 0000000000..31458a79b9
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part4/part4.pro
@@ -0,0 +1,9 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part4
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part4.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part4
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part5/addressbook.cpp b/examples/tutorials/addressbook-fr/part5/addressbook.cpp
new file mode 100644
index 0000000000..471ffa3663
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/addressbook.cpp
@@ -0,0 +1,312 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+//! [instantiating findButton]
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+//! [instantiating findButton]
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+//! [instantiating FindDialog]
+ dialog = new FindDialog;
+//! [instantiating FindDialog]
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+//! [signals and slots for find]
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+//! [signals and slots for find]
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+//! [adding findButton to layout]
+ buttonLayout1->addWidget(findButton);
+//! [adding findButton to layout]
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [findContact() function]
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == QDialog::Accepted) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [findContact() function]
+
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+ break;
+ }
+}
diff --git a/examples/tutorials/addressbook-fr/part5/addressbook.h b/examples/tutorials/addressbook-fr/part5/addressbook.h
new file mode 100644
index 0000000000..e33f63273c
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/addressbook.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+//! [include finddialog's header]
+#include "finddialog.h"
+//! [include finddialog's header]
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+//! [findContact() declaration]
+ void findContact();
+//! [findContact() declaration]
+ void next();
+ void previous();
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+//! [findButton declaration]
+ QPushButton *findButton;
+//! [findButton declaration]
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+//! [FindDialog declaration]
+ FindDialog *dialog;
+//! [FindDialog declaration]
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part5/finddialog.cpp b/examples/tutorials/addressbook-fr/part5/finddialog.cpp
new file mode 100644
index 0000000000..03d4abf1ac
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/finddialog.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+//! [constructor]
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+//! [constructor]
+//! [findClicked() function]
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+//! [findClicked() function]
+//! [getFindText() function]
+QString FindDialog::getFindText()
+{
+ return findText;
+}
+//! [getFindText() function]
diff --git a/examples/tutorials/addressbook-fr/part5/finddialog.h b/examples/tutorials/addressbook-fr/part5/finddialog.h
new file mode 100644
index 0000000000..1c154885b2
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+//! [FindDialog header]
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+//! [FindDialog header]
+#endif
diff --git a/examples/tutorials/addressbook-fr/part5/main.cpp b/examples/tutorials/addressbook-fr/part5/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook-fr/part5/part5.pro b/examples/tutorials/addressbook-fr/part5/part5.pro
new file mode 100644
index 0000000000..0899fdd90a
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part5/part5.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part5
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part5.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part5
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part6/addressbook.cpp b/examples/tutorials/addressbook-fr/part6/addressbook.cpp
new file mode 100644
index 0000000000..a085ab3bed
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/addressbook.cpp
@@ -0,0 +1,393 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ loadButton = new QPushButton(tr("&Load..."));
+//! [tooltip 1]
+ loadButton->setToolTip(tr("Load contacts from a file"));
+//! [tooltip 1]
+ saveButton = new QPushButton(tr("Sa&ve..."));
+//! [tooltip 2]
+ saveButton->setToolTip(tr("Save contacts to a file"));
+//! [tooltip 2]
+ saveButton->setEnabled(false);
+
+ dialog = new FindDialog;
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
+ connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+ buttonLayout1->addWidget(findButton);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addWidget(loadButton);
+ buttonLayout1->addWidget(saveButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == 1) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+
+ loadButton->setEnabled(false);
+ saveButton->setEnabled(false);
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+
+ loadButton->setEnabled(true);
+ saveButton->setEnabled(number >= 1);
+ break;
+ }
+}
+
+//! [saveToFile() function part1]
+void AddressBook::saveToFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+//! [saveToFile() function part1]
+//! [saveToFile() function part2]
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+//! [saveToFile() function part2]
+//! [saveToFile() function part3]
+ QDataStream out(&file);
+ out.setVersion(QDataStream::Qt_4_5);
+ out << contacts;
+ }
+}
+//! [saveToFile() function part3]
+
+//! [loadFromFile() function part1]
+void AddressBook::loadFromFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+//! [loadFromFile() function part1]
+
+//! [loadFromFile() function part2]
+ if (fileName.isEmpty())
+ return;
+ else {
+
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream in(&file);
+ in.setVersion(QDataStream::Qt_4_5);
+ contacts.empty(); // empty existing contacts
+ in >> contacts;
+//! [loadFromFile() function part2]
+
+//! [loadFromFile() function part3]
+ if (contacts.isEmpty()) {
+ QMessageBox::information(this, tr("No contacts in file"),
+ tr("The file you are attempting to open contains no contacts."));
+ } else {
+ QMap<QString, QString>::iterator i = contacts.begin();
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [loadFromFile() function part3]
diff --git a/examples/tutorials/addressbook-fr/part6/addressbook.h b/examples/tutorials/addressbook-fr/part6/addressbook.h
new file mode 100644
index 0000000000..abdc6bc8e2
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/addressbook.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+#include "finddialog.h"
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+ void findContact();
+ void next();
+ void previous();
+//! [save and load functions declaration]
+ void saveToFile();
+ void loadFromFile();
+//! [save and load functions declaration]
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+ QPushButton *findButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+//! [save and load buttons declaration]
+ QPushButton *loadButton;
+ QPushButton *saveButton;
+//! [save and load buttons declaration]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ FindDialog *dialog;
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part6/finddialog.cpp b/examples/tutorials/addressbook-fr/part6/finddialog.cpp
new file mode 100644
index 0000000000..9e4342a590
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/finddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+
+QString FindDialog::getFindText()
+{
+ return findText;
+}
diff --git a/examples/tutorials/addressbook-fr/part6/finddialog.h b/examples/tutorials/addressbook-fr/part6/finddialog.h
new file mode 100644
index 0000000000..607a4fefc6
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part6/main.cpp b/examples/tutorials/addressbook-fr/part6/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook-fr/part6/part6.pro b/examples/tutorials/addressbook-fr/part6/part6.pro
new file mode 100644
index 0000000000..df161f44fa
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part6/part6.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part6
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part6.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part6
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook-fr/part7/addressbook.cpp b/examples/tutorials/addressbook-fr/part7/addressbook.cpp
new file mode 100644
index 0000000000..68a4b4cc85
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/addressbook.cpp
@@ -0,0 +1,446 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ loadButton = new QPushButton(tr("&Load..."));
+ loadButton->setToolTip(tr("Load contacts from a file"));
+ saveButton = new QPushButton(tr("Sa&ve..."));
+ saveButton->setToolTip(tr("Save contacts to a file"));
+ saveButton->setEnabled(false);
+
+ exportButton = new QPushButton(tr("E&xport"));
+ exportButton->setToolTip(tr("Export as vCard"));
+ exportButton->setEnabled(false);
+
+ dialog = new FindDialog;
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
+ connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
+ connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+ buttonLayout1->addWidget(findButton);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addWidget(loadButton);
+ buttonLayout1->addWidget(saveButton);
+ buttonLayout1->addWidget(exportButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == 1) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+
+ loadButton->setEnabled(false);
+ saveButton->setEnabled(false);
+ exportButton->setEnabled(false);
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+
+ exportButton->setEnabled(number >= 1);
+
+ loadButton->setEnabled(true);
+ saveButton->setEnabled(number >= 1);
+ break;
+ }
+}
+
+void AddressBook::saveToFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream out(&file);
+ out.setVersion(QDataStream::Qt_4_3);
+ out << contacts;
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::loadFromFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream in(&file);
+ in.setVersion(QDataStream::Qt_4_3);
+ contacts.empty(); // empty existing contacts
+ in >> contacts;
+
+ QMap<QString, QString>::iterator i = contacts.begin();
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+ }
+
+ updateInterface(NavigationMode);
+}
+
+//! [export function part1]
+void AddressBook::exportAsVCard()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+ QString firstName;
+ QString lastName;
+ QStringList nameList;
+
+ int index = name.indexOf(" ");
+
+ if (index != -1) {
+ nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts);
+ firstName = nameList.first();
+ lastName = nameList.last();
+ } else {
+ firstName = name;
+ lastName = "";
+ }
+
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Export Contact"), "",
+ tr("vCard Files (*.vcf);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+//! [export function part1]
+
+//! [export function part2]
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QTextStream out(&file);
+//! [export function part2]
+
+//! [export function part3]
+ out << "BEGIN:VCARD" << "\n";
+ out << "VERSION:2.1" << "\n";
+ out << "N:" << lastName << ";" << firstName << "\n";
+
+ if (!nameList.isEmpty())
+ out << "FN:" << nameList.join(" ") << "\n";
+ else
+ out << "FN:" << firstName << "\n";
+//! [export function part3]
+
+//! [export function part4]
+ address.replace(";", "\\;", Qt::CaseInsensitive);
+ address.replace("\n", ";", Qt::CaseInsensitive);
+ address.replace(",", " ", Qt::CaseInsensitive);
+
+ out << "ADR;HOME:;" << address << "\n";
+ out << "END:VCARD" << "\n";
+
+ QMessageBox::information(this, tr("Export Successful"),
+ tr("\"%1\" has been exported as a vCard.").arg(name));
+}
+//! [export function part4]
diff --git a/examples/tutorials/addressbook-fr/part7/addressbook.h b/examples/tutorials/addressbook-fr/part7/addressbook.h
new file mode 100644
index 0000000000..3ab4be53fa
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/addressbook.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+#include "finddialog.h"
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+ void findContact();
+ void next();
+ void previous();
+ void saveToFile();
+ void loadFromFile();
+//! [exportAsVCard() declaration]
+ void exportAsVCard();
+//! [exportAsVCard() declaration]
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+ QPushButton *findButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QPushButton *loadButton;
+ QPushButton *saveButton;
+//! [exportButton declaration]
+ QPushButton *exportButton;
+//! [exportButton declaration]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ FindDialog *dialog;
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part7/finddialog.cpp b/examples/tutorials/addressbook-fr/part7/finddialog.cpp
new file mode 100644
index 0000000000..9e4342a590
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/finddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+
+QString FindDialog::getFindText()
+{
+ return findText;
+}
diff --git a/examples/tutorials/addressbook-fr/part7/finddialog.h b/examples/tutorials/addressbook-fr/part7/finddialog.h
new file mode 100644
index 0000000000..607a4fefc6
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook-fr/part7/main.cpp b/examples/tutorials/addressbook-fr/part7/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook-fr/part7/part7.pro b/examples/tutorials/addressbook-fr/part7/part7.pro
new file mode 100644
index 0000000000..22f4435559
--- /dev/null
+++ b/examples/tutorials/addressbook-fr/part7/part7.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part7
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part7.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part7
+INSTALLS += target sources
diff --git a/examples/tutorials/addressbook/README b/examples/tutorials/addressbook/README
new file mode 100644
index 0000000000..20ae7f3ada
--- /dev/null
+++ b/examples/tutorials/addressbook/README
@@ -0,0 +1,42 @@
+The Address Book Tutorial shows how to put together a simple yet
+fully-functioning GUI application. The tutorial chapters can be found in the
+Qt documentation, which can be viewed using Qt Assistant or a Web browser.
+
+The tutorial is also available online at
+
+http://qt.nokia.com/doc/tutorial.html
+
+All programs corresponding to the chapters in the tutorial should
+automatically be built when Qt is compiled, or will be provided as
+pre-built executables if you have obtained a binary package of Qt.
+
+If you have only compiled the Qt libraries, use the following instructions
+to build the tutorial.
+
+On Linux/Unix:
+
+Typing 'make' in this directory builds all the programs (part1/part1,
+part2/part2, part3/part3 and so on). Typing 'make' in each subdirectory
+builds just that tutorial program.
+
+On Windows:
+
+Create a single Visual Studio project for the tutorial directory in
+the usual way. You can do this by typing the following at the command
+line:
+
+qmake -tp vc
+
+You should now be able to open the project file in Visual Studio and
+build all of the tutorial programs at the same time.
+
+On Mac OS X:
+
+Create an Xcode project with the .pro file in the tutorial directory.
+You can do this by typing the following at the command line:
+
+qmake -spec macx-xcode
+
+Then open the generated Xcode project in Xcode and build it.
+
+Feel free to send comments about the tutorial to qt-bugs@trolltech.com.
diff --git a/examples/tutorials/addressbook/addressbook.pro b/examples/tutorials/addressbook/addressbook.pro
new file mode 100644
index 0000000000..0605a5b2d5
--- /dev/null
+++ b/examples/tutorials/addressbook/addressbook.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = part1 part2 part3 part4 part5 part6 part7
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS addressbook.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part1/addressbook.cpp b/examples/tutorials/addressbook/part1/addressbook.cpp
new file mode 100644
index 0000000000..7ff4c9ea79
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/addressbook.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [constructor and input fields]
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+//! [constructor and input fields]
+
+//! [layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+//! [layout]
+
+//![setting the layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+//! [setting the layout]
diff --git a/examples/tutorials/addressbook/part1/addressbook.h b/examples/tutorials/addressbook/part1/addressbook.h
new file mode 100644
index 0000000000..90b9b0ed48
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/addressbook.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [class definition]
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+private:
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+};
+//! [class definition]
+
+#endif
diff --git a/examples/tutorials/addressbook/part1/main.cpp b/examples/tutorials/addressbook/part1/main.cpp
new file mode 100644
index 0000000000..970921d537
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tutorials/addressbook/part1/part1.pro b/examples/tutorials/addressbook/part1/part1.pro
new file mode 100644
index 0000000000..113887ee30
--- /dev/null
+++ b/examples/tutorials/addressbook/part1/part1.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part1
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part1.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part1
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part2/addressbook.cpp b/examples/tutorials/addressbook/part2/addressbook.cpp
new file mode 100644
index 0000000000..5fccd12b8e
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/addressbook.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+//! [setting readonly 1]
+ nameLine->setReadOnly(true);
+//! [setting readonly 1]
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+//! [setting readonly 2]
+ addressText->setReadOnly(true);
+//! [setting readonly 2]
+
+//! [pushbutton declaration]
+ addButton = new QPushButton(tr("&Add"));
+ addButton->show();
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+//! [pushbutton declaration]
+//! [connecting signals and slots]
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+//! [connecting signals and slots]
+//! [vertical layout]
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton, Qt::AlignTop);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+//! [vertical layout]
+//! [grid layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+//! [grid layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+//! [addContact]
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ submitButton->show();
+ cancelButton->show();
+}
+//! [addContact]
+
+//! [submitContact part1]
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+//! [submitContact part1]
+//! [submitContact part2]
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ return;
+ }
+//! [submitContact part2]
+//! [submitContact part3]
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+ submitButton->hide();
+ cancelButton->hide();
+}
+//! [submitContact part3]
+//! [cancel]
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ nameLine->setReadOnly(true);
+
+ addressText->setText(oldAddress);
+ addressText->setReadOnly(true);
+
+ addButton->setEnabled(true);
+ submitButton->hide();
+ cancelButton->hide();
+}
+//! [cancel]
diff --git a/examples/tutorials/addressbook/part2/addressbook.h b/examples/tutorials/addressbook/part2/addressbook.h
new file mode 100644
index 0000000000..9f9b2b0b91
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/addressbook.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+//! [slots]
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [slots]
+
+//! [pushbutton declaration]
+private:
+ QPushButton *addButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+//! [pushbutton declaration]
+
+//! [remaining private variables]
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+};
+//! [remaining private variables]
+
+#endif
diff --git a/examples/tutorials/addressbook/part2/main.cpp b/examples/tutorials/addressbook/part2/main.cpp
new file mode 100644
index 0000000000..970921d537
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
+//! [main function]
diff --git a/examples/tutorials/addressbook/part2/part2.pro b/examples/tutorials/addressbook/part2/part2.pro
new file mode 100644
index 0000000000..4cee9a49d5
--- /dev/null
+++ b/examples/tutorials/addressbook/part2/part2.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part2
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part2.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part2
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part3/addressbook.cpp b/examples/tutorials/addressbook/part3/addressbook.cpp
new file mode 100644
index 0000000000..72ca52b199
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/addressbook.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+ addButton->show();
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+//! [navigation pushbuttons]
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+//! [navigation pushbuttons]
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+//! [connecting navigation signals]
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+//! [connecting navigation signals]
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton, Qt::AlignTop);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+//! [navigation layout]
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+//! [ navigation layout]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+//! [adding navigation layout]
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+//! [adding navigation layout]
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+//! [disabling navigation]
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+//! [disabling navigation]
+ submitButton->show();
+ cancelButton->show();
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+//! [enabling navigation]
+ int number = contacts.size();
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+//! [enabling navigation]
+ submitButton->hide();
+ cancelButton->hide();
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+}
+
+//! [next() function]
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [next() function]
+//! [previous() function]
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()){
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [previous() function]
diff --git a/examples/tutorials/addressbook/part3/addressbook.h b/examples/tutorials/addressbook/part3/addressbook.h
new file mode 100644
index 0000000000..192a5aef46
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/addressbook.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [navigation functions]
+ void next();
+ void previous();
+//! [navigation functions]
+
+private:
+ QPushButton *addButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+//! [navigation pushbuttons]
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+//! [navigation pushbuttons]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part3/main.cpp b/examples/tutorials/addressbook/part3/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook/part3/part3.pro b/examples/tutorials/addressbook/part3/part3.pro
new file mode 100644
index 0000000000..9d70d1b9c3
--- /dev/null
+++ b/examples/tutorials/addressbook/part3/part3.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part3
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part3.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part3
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part4/addressbook.cpp b/examples/tutorials/addressbook/part4/addressbook.cpp
new file mode 100644
index 0000000000..bbb5e03987
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/addressbook.cpp
@@ -0,0 +1,288 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+//! [edit and remove buttons]
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+//! [edit and remove buttons]
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+//! [connecting edit and remove]
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+//! [connecting edit and remove]
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+//! [adding edit and remove to the layout]
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+//! [adding edit and remove to the layout]
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+//! [editContact() function]
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+//! [editContact() function]
+//! [submitContact() function beginning]
+void AddressBook::submitContact()
+{
+//! [submitContact() function beginning]
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+//! [submitContact() function part1]
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+//! [submitContact() function part1]
+//! [submitContact() function part2]
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [submitContact() function part2]
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+//! [removeContact() function]
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [removeContact() function]
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [update interface() part 1]
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+ break;
+//! [update interface() part 1]
+//! [update interface() part 2]
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number >1 );
+
+ submitButton->hide();
+ cancelButton->hide();
+ break;
+ }
+}
+//! [update interface() part 2]
diff --git a/examples/tutorials/addressbook/part4/addressbook.h b/examples/tutorials/addressbook/part4/addressbook.h
new file mode 100644
index 0000000000..4d653d1fad
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/addressbook.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+//! [Mode enum]
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+//! [Mode enum]
+
+public slots:
+ void addContact();
+ void submitContact();
+ void cancel();
+//! [edit and remove slots]
+ void editContact();
+ void removeContact();
+//! [edit and remove slots]
+ void next();
+ void previous();
+
+private:
+//! [updateInterface() declaration]
+ void updateInterface(Mode mode);
+//! [updateInterface() declaration]
+ QPushButton *addButton;
+//! [buttons declaration]
+ QPushButton *editButton;
+ QPushButton *removeButton;
+//! [buttons declaration]
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ QString oldName;
+ QString oldAddress;
+//! [mode declaration]
+ Mode currentMode;
+//! [mode declaration]
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part4/main.cpp b/examples/tutorials/addressbook/part4/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook/part4/part4.pro b/examples/tutorials/addressbook/part4/part4.pro
new file mode 100644
index 0000000000..231425803a
--- /dev/null
+++ b/examples/tutorials/addressbook/part4/part4.pro
@@ -0,0 +1,11 @@
+SOURCES = addressbook.cpp \
+ main.cpp
+HEADERS = addressbook.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part4
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part4.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part4
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part5/addressbook.cpp b/examples/tutorials/addressbook/part5/addressbook.cpp
new file mode 100644
index 0000000000..7489e7c9db
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/addressbook.cpp
@@ -0,0 +1,312 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+//! [instantiating findButton]
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+//! [instantiating findButton]
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+//! [instantiating FindDialog]
+ dialog = new FindDialog;
+//! [instantiating FindDialog]
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+//! [signals and slots for find]
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+//! [signals and slots for find]
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+//! [adding findButton to layout]
+ buttonLayout1->addWidget(findButton);
+//! [adding findButton to layout]
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+//! [findContact() function]
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == QDialog::Accepted) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [findContact() function]
+
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+ break;
+ }
+}
diff --git a/examples/tutorials/addressbook/part5/addressbook.h b/examples/tutorials/addressbook/part5/addressbook.h
new file mode 100644
index 0000000000..e33f63273c
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/addressbook.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+//! [include finddialog's header]
+#include "finddialog.h"
+//! [include finddialog's header]
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+//! [findContact() declaration]
+ void findContact();
+//! [findContact() declaration]
+ void next();
+ void previous();
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+//! [findButton declaration]
+ QPushButton *findButton;
+//! [findButton declaration]
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+//! [FindDialog declaration]
+ FindDialog *dialog;
+//! [FindDialog declaration]
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part5/finddialog.cpp b/examples/tutorials/addressbook/part5/finddialog.cpp
new file mode 100644
index 0000000000..03d4abf1ac
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/finddialog.cpp
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+//! [constructor]
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+//! [constructor]
+//! [findClicked() function]
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+//! [findClicked() function]
+//! [getFindText() function]
+QString FindDialog::getFindText()
+{
+ return findText;
+}
+//! [getFindText() function]
diff --git a/examples/tutorials/addressbook/part5/finddialog.h b/examples/tutorials/addressbook/part5/finddialog.h
new file mode 100644
index 0000000000..1c154885b2
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+//! [FindDialog header]
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+//! [FindDialog header]
+#endif
diff --git a/examples/tutorials/addressbook/part5/main.cpp b/examples/tutorials/addressbook/part5/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook/part5/part5.pro b/examples/tutorials/addressbook/part5/part5.pro
new file mode 100644
index 0000000000..f44362e942
--- /dev/null
+++ b/examples/tutorials/addressbook/part5/part5.pro
@@ -0,0 +1,13 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part5
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part5.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part5
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part6/addressbook.cpp b/examples/tutorials/addressbook/part6/addressbook.cpp
new file mode 100644
index 0000000000..c7dc8e219b
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/addressbook.cpp
@@ -0,0 +1,393 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ loadButton = new QPushButton(tr("&Load..."));
+//! [tooltip 1]
+ loadButton->setToolTip(tr("Load contacts from a file"));
+//! [tooltip 1]
+ saveButton = new QPushButton(tr("&Save..."));
+//! [tooltip 2]
+ saveButton->setToolTip(tr("Save contacts to a file"));
+//! [tooltip 2]
+ saveButton->setEnabled(false);
+
+ dialog = new FindDialog;
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
+ connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+ buttonLayout1->addWidget(findButton);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addWidget(loadButton);
+ buttonLayout1->addWidget(saveButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == 1) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+
+ loadButton->setEnabled(false);
+ saveButton->setEnabled(false);
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+
+ loadButton->setEnabled(true);
+ saveButton->setEnabled(number >= 1);
+ break;
+ }
+}
+
+//! [saveToFile() function part1]
+void AddressBook::saveToFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+//! [saveToFile() function part1]
+//! [saveToFile() function part2]
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+//! [saveToFile() function part2]
+//! [saveToFile() function part3]
+ QDataStream out(&file);
+ out.setVersion(QDataStream::Qt_4_5);
+ out << contacts;
+ }
+}
+//! [saveToFile() function part3]
+
+//! [loadFromFile() function part1]
+void AddressBook::loadFromFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+//! [loadFromFile() function part1]
+
+//! [loadFromFile() function part2]
+ if (fileName.isEmpty())
+ return;
+ else {
+
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream in(&file);
+ in.setVersion(QDataStream::Qt_4_5);
+ contacts.empty(); // empty existing contacts
+ in >> contacts;
+//! [loadFromFile() function part2]
+
+//! [loadFromFile() function part3]
+ if (contacts.isEmpty()) {
+ QMessageBox::information(this, tr("No contacts in file"),
+ tr("The file you are attempting to open contains no contacts."));
+ } else {
+ QMap<QString, QString>::iterator i = contacts.begin();
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+//! [loadFromFile() function part3]
diff --git a/examples/tutorials/addressbook/part6/addressbook.h b/examples/tutorials/addressbook/part6/addressbook.h
new file mode 100644
index 0000000000..abdc6bc8e2
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/addressbook.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+#include "finddialog.h"
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+ void findContact();
+ void next();
+ void previous();
+//! [save and load functions declaration]
+ void saveToFile();
+ void loadFromFile();
+//! [save and load functions declaration]
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+ QPushButton *findButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+//! [save and load buttons declaration]
+ QPushButton *loadButton;
+ QPushButton *saveButton;
+//! [save and load buttons declaration]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ FindDialog *dialog;
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part6/finddialog.cpp b/examples/tutorials/addressbook/part6/finddialog.cpp
new file mode 100644
index 0000000000..9e4342a590
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/finddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+
+QString FindDialog::getFindText()
+{
+ return findText;
+}
diff --git a/examples/tutorials/addressbook/part6/finddialog.h b/examples/tutorials/addressbook/part6/finddialog.h
new file mode 100644
index 0000000000..607a4fefc6
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part6/main.cpp b/examples/tutorials/addressbook/part6/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook/part6/part6.pro b/examples/tutorials/addressbook/part6/part6.pro
new file mode 100644
index 0000000000..0eec36ef21
--- /dev/null
+++ b/examples/tutorials/addressbook/part6/part6.pro
@@ -0,0 +1,13 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part6
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part6.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part6
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/addressbook/part7/addressbook.cpp b/examples/tutorials/addressbook/part7/addressbook.cpp
new file mode 100644
index 0000000000..501ad31c5c
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/addressbook.cpp
@@ -0,0 +1,446 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+AddressBook::AddressBook(QWidget *parent)
+ : QWidget(parent)
+{
+ QLabel *nameLabel = new QLabel(tr("Name:"));
+ nameLine = new QLineEdit;
+ nameLine->setReadOnly(true);
+
+ QLabel *addressLabel = new QLabel(tr("Address:"));
+ addressText = new QTextEdit;
+ addressText->setReadOnly(true);
+
+ addButton = new QPushButton(tr("&Add"));
+
+ editButton = new QPushButton(tr("&Edit"));
+ editButton->setEnabled(false);
+ removeButton = new QPushButton(tr("&Remove"));
+ removeButton->setEnabled(false);
+ findButton = new QPushButton(tr("&Find"));
+ findButton->setEnabled(false);
+ submitButton = new QPushButton(tr("&Submit"));
+ submitButton->hide();
+ cancelButton = new QPushButton(tr("&Cancel"));
+ cancelButton->hide();
+
+ nextButton = new QPushButton(tr("&Next"));
+ nextButton->setEnabled(false);
+ previousButton = new QPushButton(tr("&Previous"));
+ previousButton->setEnabled(false);
+
+ loadButton = new QPushButton(tr("&Load..."));
+ loadButton->setToolTip(tr("Load contacts from a file"));
+ saveButton = new QPushButton(tr("&Save..."));
+ saveButton->setToolTip(tr("Save contacts to a file"));
+ saveButton->setEnabled(false);
+
+ exportButton = new QPushButton(tr("E&xport"));
+ exportButton->setToolTip(tr("Export as vCard"));
+ exportButton->setEnabled(false);
+
+ dialog = new FindDialog;
+
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
+ connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
+ connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
+ connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile()));
+ connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
+ connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard()));
+
+ QVBoxLayout *buttonLayout1 = new QVBoxLayout;
+ buttonLayout1->addWidget(addButton);
+ buttonLayout1->addWidget(editButton);
+ buttonLayout1->addWidget(removeButton);
+ buttonLayout1->addWidget(findButton);
+ buttonLayout1->addWidget(submitButton);
+ buttonLayout1->addWidget(cancelButton);
+ buttonLayout1->addWidget(loadButton);
+ buttonLayout1->addWidget(saveButton);
+ buttonLayout1->addWidget(exportButton);
+ buttonLayout1->addStretch();
+
+ QHBoxLayout *buttonLayout2 = new QHBoxLayout;
+ buttonLayout2->addWidget(previousButton);
+ buttonLayout2->addWidget(nextButton);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameLine, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
+ mainLayout->addWidget(addressText, 1, 1);
+ mainLayout->addLayout(buttonLayout1, 1, 2);
+ mainLayout->addLayout(buttonLayout2, 2, 1);
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("Simple Address Book"));
+}
+
+void AddressBook::addContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ nameLine->clear();
+ addressText->clear();
+
+ updateInterface(AddingMode);
+}
+
+void AddressBook::editContact()
+{
+ oldName = nameLine->text();
+ oldAddress = addressText->toPlainText();
+
+ updateInterface(EditingMode);
+}
+
+void AddressBook::submitContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (name.isEmpty() || address.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name and address."));
+ return;
+ }
+
+ if (currentMode == AddingMode) {
+
+ if (!contacts.contains(name)) {
+ contacts.insert(name, address);
+ QMessageBox::information(this, tr("Add Successful"),
+ tr("\"%1\" has been added to your address book.").arg(name));
+ } else {
+ QMessageBox::information(this, tr("Add Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (currentMode == EditingMode) {
+
+ if (oldName != name) {
+ if (!contacts.contains(name)) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(oldName));
+ contacts.remove(oldName);
+ contacts.insert(name, address);
+ } else {
+ QMessageBox::information(this, tr("Edit Unsuccessful"),
+ tr("Sorry, \"%1\" is already in your address book.").arg(name));
+ }
+ } else if (oldAddress != address) {
+ QMessageBox::information(this, tr("Edit Successful"),
+ tr("\"%1\" has been edited in your address book.").arg(name));
+ contacts[name] = address;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::cancel()
+{
+ nameLine->setText(oldName);
+ addressText->setText(oldAddress);
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::removeContact()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+
+ if (contacts.contains(name)) {
+
+ int button = QMessageBox::question(this,
+ tr("Confirm Remove"),
+ tr("Are you sure you want to remove \"%1\"?").arg(name),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (button == QMessageBox::Yes) {
+
+ previous();
+ contacts.remove(name);
+
+ QMessageBox::information(this, tr("Remove Successful"),
+ tr("\"%1\" has been removed from your address book.").arg(name));
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::next()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i != contacts.end())
+ i++;
+
+ if (i == contacts.end())
+ i = contacts.begin();
+
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::previous()
+{
+ QString name = nameLine->text();
+ QMap<QString, QString>::iterator i = contacts.find(name);
+
+ if (i == contacts.end()) {
+ nameLine->clear();
+ addressText->clear();
+ return;
+ }
+
+ if (i == contacts.begin())
+ i = contacts.end();
+
+ i--;
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+}
+
+void AddressBook::findContact()
+{
+ dialog->show();
+
+ if (dialog->exec() == 1) {
+ QString contactName = dialog->getFindText();
+
+ if (contacts.contains(contactName)) {
+ nameLine->setText(contactName);
+ addressText->setText(contacts.value(contactName));
+ } else {
+ QMessageBox::information(this, tr("Contact Not Found"),
+ tr("Sorry, \"%1\" is not in your address book.").arg(contactName));
+ return;
+ }
+ }
+
+ updateInterface(NavigationMode);
+}
+void AddressBook::updateInterface(Mode mode)
+{
+ currentMode = mode;
+
+ switch (currentMode) {
+
+ case AddingMode:
+ case EditingMode:
+
+ nameLine->setReadOnly(false);
+ nameLine->setFocus(Qt::OtherFocusReason);
+ addressText->setReadOnly(false);
+
+ addButton->setEnabled(false);
+ editButton->setEnabled(false);
+ removeButton->setEnabled(false);
+
+ nextButton->setEnabled(false);
+ previousButton->setEnabled(false);
+
+ submitButton->show();
+ cancelButton->show();
+
+ loadButton->setEnabled(false);
+ saveButton->setEnabled(false);
+ exportButton->setEnabled(false);
+ break;
+
+ case NavigationMode:
+
+ if (contacts.isEmpty()) {
+ nameLine->clear();
+ addressText->clear();
+ }
+
+ nameLine->setReadOnly(true);
+ addressText->setReadOnly(true);
+ addButton->setEnabled(true);
+
+ int number = contacts.size();
+ editButton->setEnabled(number >= 1);
+ removeButton->setEnabled(number >= 1);
+ findButton->setEnabled(number > 2);
+ nextButton->setEnabled(number > 1);
+ previousButton->setEnabled(number > 1);
+
+ submitButton->hide();
+ cancelButton->hide();
+
+ exportButton->setEnabled(number >= 1);
+
+ loadButton->setEnabled(true);
+ saveButton->setEnabled(number >= 1);
+ break;
+ }
+}
+
+void AddressBook::saveToFile()
+{
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream out(&file);
+ out.setVersion(QDataStream::Qt_4_3);
+ out << contacts;
+ }
+
+ updateInterface(NavigationMode);
+}
+
+void AddressBook::loadFromFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open Address Book"), "",
+ tr("Address Book (*.abk);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+ else {
+ QFile file(fileName);
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QDataStream in(&file);
+ in.setVersion(QDataStream::Qt_4_3);
+ contacts.empty(); // empty existing contacts
+ in >> contacts;
+
+ QMap<QString, QString>::iterator i = contacts.begin();
+ nameLine->setText(i.key());
+ addressText->setText(i.value());
+ }
+
+ updateInterface(NavigationMode);
+}
+
+//! [export function part1]
+void AddressBook::exportAsVCard()
+{
+ QString name = nameLine->text();
+ QString address = addressText->toPlainText();
+ QString firstName;
+ QString lastName;
+ QStringList nameList;
+
+ int index = name.indexOf(" ");
+
+ if (index != -1) {
+ nameList = name.split(QRegExp("\\s+"), QString::SkipEmptyParts);
+ firstName = nameList.first();
+ lastName = nameList.last();
+ } else {
+ firstName = name;
+ lastName = "";
+ }
+
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Export Contact"), "",
+ tr("vCard Files (*.vcf);;All Files (*)"));
+
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+//! [export function part1]
+
+//! [export function part2]
+ if (!file.open(QIODevice::WriteOnly)) {
+ QMessageBox::information(this, tr("Unable to open file"),
+ file.errorString());
+ return;
+ }
+
+ QTextStream out(&file);
+//! [export function part2]
+
+//! [export function part3]
+ out << "BEGIN:VCARD" << "\n";
+ out << "VERSION:2.1" << "\n";
+ out << "N:" << lastName << ";" << firstName << "\n";
+
+ if (!nameList.isEmpty())
+ out << "FN:" << nameList.join(" ") << "\n";
+ else
+ out << "FN:" << firstName << "\n";
+//! [export function part3]
+
+//! [export function part4]
+ address.replace(";", "\\;", Qt::CaseInsensitive);
+ address.replace("\n", ";", Qt::CaseInsensitive);
+ address.replace(",", " ", Qt::CaseInsensitive);
+
+ out << "ADR;HOME:;" << address << "\n";
+ out << "END:VCARD" << "\n";
+
+ QMessageBox::information(this, tr("Export Successful"),
+ tr("\"%1\" has been exported as a vCard.").arg(name));
+}
+//! [export function part4]
diff --git a/examples/tutorials/addressbook/part7/addressbook.h b/examples/tutorials/addressbook/part7/addressbook.h
new file mode 100644
index 0000000000..3ab4be53fa
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/addressbook.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ADDRESSBOOK_H
+#define ADDRESSBOOK_H
+
+#include <QWidget>
+#include <QMap>
+#include "finddialog.h"
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+QT_END_NAMESPACE
+
+
+class AddressBook : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AddressBook(QWidget *parent = 0);
+ enum Mode { NavigationMode, AddingMode, EditingMode };
+
+public slots:
+ void addContact();
+ void editContact();
+ void submitContact();
+ void cancel();
+ void removeContact();
+ void findContact();
+ void next();
+ void previous();
+ void saveToFile();
+ void loadFromFile();
+//! [exportAsVCard() declaration]
+ void exportAsVCard();
+//! [exportAsVCard() declaration]
+
+private:
+ void updateInterface(Mode mode);
+
+ QPushButton *addButton;
+ QPushButton *editButton;
+ QPushButton *removeButton;
+ QPushButton *findButton;
+ QPushButton *submitButton;
+ QPushButton *cancelButton;
+ QPushButton *nextButton;
+ QPushButton *previousButton;
+ QPushButton *loadButton;
+ QPushButton *saveButton;
+//! [exportButton declaration]
+ QPushButton *exportButton;
+//! [exportButton declaration]
+ QLineEdit *nameLine;
+ QTextEdit *addressText;
+
+ QMap<QString, QString> contacts;
+ FindDialog *dialog;
+ QString oldName;
+ QString oldAddress;
+ Mode currentMode;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part7/finddialog.cpp b/examples/tutorials/addressbook/part7/finddialog.cpp
new file mode 100644
index 0000000000..9e4342a590
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/finddialog.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "finddialog.h"
+
+FindDialog::FindDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
+ lineEdit = new QLineEdit;
+
+ findButton = new QPushButton(tr("&Find"));
+ findText = "";
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(findLabel);
+ layout->addWidget(lineEdit);
+ layout->addWidget(findButton);
+
+ setLayout(layout);
+ setWindowTitle(tr("Find a Contact"));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
+ connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
+}
+
+void FindDialog::findClicked()
+{
+ QString text = lineEdit->text();
+
+ if (text.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Field"),
+ tr("Please enter a name."));
+ return;
+ } else {
+ findText = text;
+ lineEdit->clear();
+ hide();
+ }
+}
+
+QString FindDialog::getFindText()
+{
+ return findText;
+}
diff --git a/examples/tutorials/addressbook/part7/finddialog.h b/examples/tutorials/addressbook/part7/finddialog.h
new file mode 100644
index 0000000000..607a4fefc6
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/finddialog.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FINDDIALOG_H
+#define FINDDIALOG_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QPushButton;
+QT_END_NAMESPACE
+
+class FindDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FindDialog(QWidget *parent = 0);
+ QString getFindText();
+
+public slots:
+ void findClicked();
+
+private:
+ QPushButton *findButton;
+ QLineEdit *lineEdit;
+ QString findText;
+};
+
+#endif
diff --git a/examples/tutorials/addressbook/part7/main.cpp b/examples/tutorials/addressbook/part7/main.cpp
new file mode 100644
index 0000000000..2c92e255b8
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "addressbook.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AddressBook addressBook;
+ addressBook.show();
+
+ return app.exec();
+}
diff --git a/examples/tutorials/addressbook/part7/part7.pro b/examples/tutorials/addressbook/part7/part7.pro
new file mode 100644
index 0000000000..81a5d5cebe
--- /dev/null
+++ b/examples/tutorials/addressbook/part7/part7.pro
@@ -0,0 +1,13 @@
+SOURCES = addressbook.cpp \
+ finddialog.cpp \
+ main.cpp
+HEADERS = addressbook.h \
+ finddialog.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part7
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS part7.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/addressbook/part7
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/gettingStarted/gettingStarted.pro b/examples/tutorials/gettingStarted/gettingStarted.pro
new file mode 100644
index 0000000000..9d10f0f67a
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gettingStarted.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS +=
diff --git a/examples/tutorials/gettingStarted/gsQt/gsqt.pro b/examples/tutorials/gettingStarted/gsQt/gsqt.pro
new file mode 100755
index 0000000000..ee632f96ff
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/gsqt.pro
@@ -0,0 +1,13 @@
+TEMPLATE = subdirs
+
+SUBDIRS = part1 \
+ part2 \
+ part3 \
+ part4 \
+ part5
+
+# install
+sources.files = *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/gettingStarted/gsQt
+INSTALLS += sources
+
diff --git a/examples/tutorials/gettingStarted/gsQt/part1/main.cpp b/examples/tutorials/gettingStarted/gsQt/part1/main.cpp
new file mode 100755
index 0000000000..eaf04256d9
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/part1/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ QTextEdit textEdit;
+ textEdit.show();
+
+ return app.exec();
+}
+
diff --git a/examples/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/tutorials/gettingStarted/gsQt/part2/main.cpp
new file mode 100755
index 0000000000..24b4d77abc
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/part2/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ QTextEdit textEdit;
+ QPushButton quitButton("&Quit");
+
+ QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
+
+ QVBoxLayout layout;
+ layout.addWidget(&textEdit);
+ layout.addWidget(&quitButton);
+
+ QWidget window;
+ window.setLayout(&layout);
+
+ window.show();
+
+ return app.exec();
+}
+
diff --git a/examples/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/tutorials/gettingStarted/gsQt/part3/main.cpp
new file mode 100755
index 0000000000..59ff9c40ea
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/part3/main.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+class Notepad : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Notepad();
+
+private slots:
+ void quit();
+
+private:
+ QTextEdit *textEdit;
+ QPushButton *quitButton;
+
+};
+
+Notepad::Notepad()
+{
+ textEdit = new QTextEdit;
+ quitButton = new QPushButton(tr("Quit"));
+
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(textEdit);
+ layout->addWidget(quitButton);
+
+ setLayout(layout);
+
+ setWindowTitle(tr("Notepad"));
+}
+
+void Notepad::quit()
+{
+ QMessageBox messageBox;
+ messageBox.setWindowTitle(tr("Notepad"));
+ messageBox.setText(tr("Do you really want to quit?"));
+ messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ messageBox.setDefaultButton(QMessageBox::No);
+ if (messageBox.exec() == QMessageBox::Yes)
+ qApp->quit();
+}
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Notepad notepad;
+ notepad.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
+
diff --git a/examples/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/tutorials/gettingStarted/gsQt/part4/main.cpp
new file mode 100755
index 0000000000..ba18afb749
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/part4/main.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+class Notepad : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ Notepad();
+
+private slots:
+ void load();
+ void save();
+
+private:
+ QTextEdit *textEdit;
+
+ QAction *loadAction;
+ QAction *saveAction;
+ QAction *exitAction;
+
+ QMenu *fileMenu;
+};
+
+Notepad::Notepad()
+{
+
+ loadAction = new QAction(tr("&Load"), this);
+ saveAction = new QAction(tr("&Save"), this);
+ exitAction = new QAction(tr("E&xit"), this);
+
+ connect(loadAction, SIGNAL(triggered()), this, SLOT(load()));
+ connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(loadAction);
+ fileMenu->addAction(saveAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAction);
+
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ setWindowTitle(tr("Notepad"));
+}
+
+void Notepad::load()
+{
+
+}
+
+void Notepad::save()
+{
+
+}
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Notepad notepad;
+ notepad.show();
+
+ return app.exec();
+};
+
+#include "main.moc"
+
diff --git a/examples/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/tutorials/gettingStarted/gsQt/part5/main.cpp
new file mode 100755
index 0000000000..4a6257d10e
--- /dev/null
+++ b/examples/tutorials/gettingStarted/gsQt/part5/main.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+class Notepad : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ Notepad();
+
+private slots:
+ void open();
+ void save();
+
+private:
+ QTextEdit *textEdit;
+
+ QAction *openAction;
+ QAction *saveAction;
+ QAction *exitAction;
+
+ QMenu *fileMenu;
+};
+
+Notepad::Notepad()
+{
+
+ openAction = new QAction(tr("&Load"), this);
+ saveAction = new QAction(tr("&Save"), this);
+ exitAction = new QAction(tr("E&xit"), this);
+
+ connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
+ connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
+ connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAction);
+ fileMenu->addAction(saveAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAction);
+
+ textEdit = new QTextEdit;
+ setCentralWidget(textEdit);
+
+ setWindowTitle(tr("Notepad"));
+}
+
+void Notepad::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
+ tr("Text Files (*.txt);;C++ Files (*.cpp *.h)"));
+
+ if (fileName != "") {
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly)) {
+ QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
+ return;
+ }
+ QTextStream in(&file);
+ textEdit->setText(in.readAll());
+ file.close();
+ }
+}
+
+void Notepad::save()
+{
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "",
+ tr("Text Files (*.txt);;C++ Files (*.cpp *.h)"));
+
+ if (fileName != "") {
+ QFile file(fileName);
+ if (!file.open(QIODevice::WriteOnly)) {
+ // error message
+ } else {
+ QTextStream stream(&file);
+ stream << textEdit->toPlainText();
+ stream.flush();
+ file.close();
+ }
+ }
+}
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ Notepad notepad;
+ notepad.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
+
diff --git a/examples/tutorials/modelview/1_readonly/1_readonly.pro b/examples/tutorials/modelview/1_readonly/1_readonly.pro
new file mode 100755
index 0000000000..8ef0bdca5e
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/1_readonly.pro
@@ -0,0 +1,17 @@
+TARGET = mv_readonly
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/1_readonly
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 1_readonly.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/1_readonly
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp
new file mode 100755
index 0000000000..fdde141b4c
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [Quoting ModelView Tutorial]
+// main.cpp
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp
new file mode 100755
index 0000000000..9b5bdd7df2
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [Quoting ModelView Tutorial]
+// mymodel.cpp
+#include "mymodel.h"
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return 2;
+}
+
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return 3;
+}
+
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return QString("Row%1, Column%2")
+ .arg(index.row() + 1)
+ .arg(index.column() +1);
+ }
+ return QVariant();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h
new file mode 100755
index 0000000000..f60546897a
--- /dev/null
+++ b/examples/tutorials/modelview/1_readonly/mymodel.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+//! [Quoting ModelView Tutorial]
+// mymodel.h
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+//! [Quoting ModelView Tutorial]
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/2_formatting/2_formatting.pro b/examples/tutorials/modelview/2_formatting/2_formatting.pro
new file mode 100755
index 0000000000..f8babd5799
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/2_formatting.pro
@@ -0,0 +1,16 @@
+TARGET = mv_formatting
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/2_formatting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 2_formatting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/2_formatting
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/2_formatting/main.cpp b/examples/tutorials/modelview/2_formatting/main.cpp
new file mode 100755
index 0000000000..fdde141b4c
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [Quoting ModelView Tutorial]
+// main.cpp
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp
new file mode 100755
index 0000000000..8363af9252
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QFont>
+#include <QBrush>
+#include "mymodel.h"
+#include <QDebug>
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+int MyModel::rowCount(const QModelIndex & /*parent */) const
+{
+ return 2;
+}
+
+int MyModel::columnCount(const QModelIndex & /*parent */) const
+{
+ return 3;
+}
+
+//! [Quoting ModelView Tutorial]
+// mymodel.cpp
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ int row = index.row();
+ int col = index.column();
+ // generate a log message when this method gets called
+ qDebug() << QString("row %1, col%2, role %3")
+ .arg(row).arg(col).arg(role);
+
+ switch(role){
+ case Qt::DisplayRole:
+ if (row == 0 && col == 1) return QString("<--left");
+ if (row == 1 && col == 1) return QString("right-->");
+
+ return QString("Row%1, Column%2")
+ .arg(row + 1)
+ .arg(col +1);
+ break;
+ case Qt::FontRole:
+ if (row == 0 && col == 0) //change font only for cell(0,0)
+ {
+ QFont boldFont;
+ boldFont.setBold(true);
+ return boldFont;
+ }
+ break;
+ case Qt::BackgroundRole:
+
+ if (row == 1 && col == 2) //change background only for cell(1,2)
+ {
+ QBrush redBackground(Qt::red);
+ return redBackground;
+ }
+ break;
+ case Qt::TextAlignmentRole:
+
+ if (row == 1 && col == 1) //change text alignment only for cell(1,1)
+ {
+ return Qt::AlignRight + Qt::AlignVCenter;
+ }
+ break;
+ case Qt::CheckStateRole:
+
+ if (row == 1 && col == 0) //add a checkbox to cell(1,0)
+ {
+ return Qt::Checked;
+ }
+ }
+ return QVariant();
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/2_formatting/mymodel.h b/examples/tutorials/modelview/2_formatting/mymodel.h
new file mode 100755
index 0000000000..7ad876c1bf
--- /dev/null
+++ b/examples/tutorials/modelview/2_formatting/mymodel.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro
new file mode 100755
index 0000000000..205571d4e1
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/3_changingmodel.pro
@@ -0,0 +1,16 @@
+TARGET = mv_changingmodel
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/3_changingmodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 3_changingmodel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/3_changingmodel
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/3_changingmodel/main.cpp b/examples/tutorials/modelview/3_changingmodel/main.cpp
new file mode 100755
index 0000000000..8a4ab8f6ab
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
new file mode 100755
index 0000000000..fa50005701
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QBrush>
+#include <QTime>
+#include "mymodel.h"
+
+//! [quoting mymodel_a]
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+// selectedCell = 0;
+ timer = new QTimer(this);
+ timer->setInterval(1000);
+ connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()));
+ timer->start();
+}
+//! [quoting mymodel_a]
+//-------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent */) const
+{
+ return 2;
+}
+
+//-------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent */) const
+{
+ return 3;
+}
+
+//-------------------------------------------------------
+//! [quoting mymodel_QVariant ]
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ int row = index.row();
+ int col = index.column();
+
+ if (role == Qt::DisplayRole)
+ {
+ if (row == 0 && col == 0)
+ {
+ return QTime::currentTime().toString();
+ }
+ }
+ return QVariant();
+}
+//! [quoting mymodel_QVariant ]
+//-------------------------------------------------------
+//! [quoting mymodel_b ]
+void MyModel::timerHit()
+{
+ //we identify the top left cell
+ QModelIndex topLeft = createIndex(0,0);
+ //emit a signal to make the view reread identified data
+ emit dataChanged(topLeft, topLeft);
+}
+//! [quoting mymodel_b ]
diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.h b/examples/tutorials/modelview/3_changingmodel/mymodel.h
new file mode 100755
index 0000000000..be59c59207
--- /dev/null
+++ b/examples/tutorials/modelview/3_changingmodel/mymodel.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+#include <QTimer>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ QTimer *timer;
+private:
+ int selectedCell;
+private slots:
+ void timerHit();
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/4_headers/4_headers.pro b/examples/tutorials/modelview/4_headers/4_headers.pro
new file mode 100755
index 0000000000..d3004e39d2
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/4_headers.pro
@@ -0,0 +1,16 @@
+TARGET = mv_headers
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mymodel.cpp
+
+HEADERS += mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/4_headers
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 4_headers.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/4_headers
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/4_headers/main.cpp b/examples/tutorials/modelview/4_headers/main.cpp
new file mode 100755
index 0000000000..c89829ab42
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtGui/QTableView>
+#include "mymodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QTableView tableView;
+ MyModel myModel(0);
+ tableView.setModel( &myModel );
+ tableView.show();
+ return a.exec();
+} \ No newline at end of file
diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp
new file mode 100755
index 0000000000..ee0e609228
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/mymodel.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mymodel.h"
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+//-------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return 2;
+}
+
+//-------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return 3;
+}
+
+//-------------------------------------------------------
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return QString("Row%1, Column%2")
+ .arg(index.row() + 1)
+ .arg(index.column() +1);
+ }
+ return QVariant();
+}
+
+//! [quoting mymodel_c]
+QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ if (orientation == Qt::Horizontal) {
+ switch (section)
+ {
+ case 0:
+ return QString("first");
+ case 1:
+ return QString("second");
+ case 2:
+ return QString("third");
+ }
+ }
+ }
+ return QVariant();
+}
+//! [quoting mymodel_c]
diff --git a/examples/tutorials/modelview/4_headers/mymodel.h b/examples/tutorials/modelview/4_headers/mymodel.h
new file mode 100755
index 0000000000..5a185d92e4
--- /dev/null
+++ b/examples/tutorials/modelview/4_headers/mymodel.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+#include <QAbstractTableModel>
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ 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) const;
+};
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/5_edit/5_edit.pro b/examples/tutorials/modelview/5_edit/5_edit.pro
new file mode 100755
index 0000000000..d2fb983a13
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/5_edit.pro
@@ -0,0 +1,18 @@
+TARGET = mv_edit
+
+TEMPLATE = app
+
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ mymodel.cpp
+
+HEADERS += mainwindow.h \
+ mymodel.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/5_edit
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 5_edit.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/5_edit
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/5_edit/main.cpp b/examples/tutorials/modelview/5_edit/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/5_edit/mainwindow.cpp b/examples/tutorials/modelview/5_edit/mainwindow.cpp
new file mode 100755
index 0000000000..4b7e59a290
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mainwindow.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QTableView>
+#include "mainwindow.h"
+#include "mymodel.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ tableView = new QTableView(this);
+ setCentralWidget(tableView);
+ QAbstractTableModel *myModel = new MyModel(this);
+ tableView->setModel(myModel);
+
+ //transfer changes to the model to the window title
+ connect(myModel, SIGNAL(editCompleted(const QString &)), this, SLOT(setWindowTitle(const QString &)));
+}
+
+void MainWindow::showWindowTitle(const QString & title)
+{
+setWindowTitle(title);
+}
diff --git a/examples/tutorials/modelview/5_edit/mainwindow.h b/examples/tutorials/modelview/5_edit/mainwindow.h
new file mode 100755
index 0000000000..37303f8293
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mainwindow.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTableView; //forward declaration
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTableView *tableView;
+public:
+ MainWindow(QWidget *parent = 0);
+public slots:
+ void showWindowTitle(const QString & title);
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp
new file mode 100755
index 0000000000..e5d20949b3
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mymodel.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "mymodel.h"
+
+
+MyModel::MyModel(QObject *parent)
+ :QAbstractTableModel(parent)
+{
+}
+
+//-----------------------------------------------------------------
+int MyModel::rowCount(const QModelIndex & /*parent*/) const
+{
+ return ROWS;
+}
+
+//-----------------------------------------------------------------
+int MyModel::columnCount(const QModelIndex & /*parent*/) const
+{
+ return COLS;
+}
+
+//-----------------------------------------------------------------
+QVariant MyModel::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole)
+ {
+ return m_gridData[index.row()][index.column()];
+ }
+ return QVariant();
+}
+
+//-----------------------------------------------------------------
+//! [quoting mymodel_e]
+bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role)
+{
+ if (role == Qt::EditRole)
+ {
+ //save value from editor to member m_gridData
+ m_gridData[index.row()][index.column()] = value.toString();
+ //for presentation purposes only: build and emit a joined string
+ QString result;
+ for(int row= 0; row < ROWS; row++)
+ {
+ for(int col= 0; col < COLS; col++)
+ {
+ result += m_gridData[row][col] + " ";
+ }
+ }
+ emit editCompleted( result );
+ }
+ return true;
+}
+//! [quoting mymodel_e]
+
+//-----------------------------------------------------------------
+//! [quoting mymodel_f]
+Qt::ItemFlags MyModel::flags(const QModelIndex & /*index*/) const
+{
+ return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ;
+}
+//! [quoting mymodel_f]
diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h
new file mode 100755
index 0000000000..ecfd58ef6b
--- /dev/null
+++ b/examples/tutorials/modelview/5_edit/mymodel.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MYMODEL_H
+#define MYMODEL_H
+
+//! [Quoting ModelView Tutorial]
+// mymodel.h
+#include <QAbstractTableModel>
+#include <QString>
+
+const int COLS= 3;
+const int ROWS= 2;
+
+
+class MyModel : public QAbstractTableModel
+{
+ Q_OBJECT
+public:
+ MyModel(QObject *parent);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
+ Qt::ItemFlags flags(const QModelIndex & index) const ;
+private:
+ QString m_gridData[ROWS][COLS]; //holds text entered into QTableView
+signals:
+ void editCompleted(const QString &);
+};
+//! [Quoting ModelView Tutorial]
+
+#endif // MYMODEL_H
diff --git a/examples/tutorials/modelview/6_treeview/6_treeview.pro b/examples/tutorials/modelview/6_treeview/6_treeview.pro
new file mode 100755
index 0000000000..63b43e06da
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/6_treeview.pro
@@ -0,0 +1,13 @@
+TARGET = mv_tree
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp
+HEADERS += mainwindow.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/6_treeview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 6_treeview.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/6_treeview
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/6_treeview/main.cpp b/examples/tutorials/modelview/6_treeview/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/6_treeview/mainwindow.cpp b/examples/tutorials/modelview/6_treeview/mainwindow.cpp
new file mode 100755
index 0000000000..0fa8da0ec4
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/mainwindow.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [Quoting ModelView Tutorial]
+// modelview.cpp
+#include <QTreeView>
+#include <QStandardItemModel>
+#include <QStandardItem>
+#include "mainwindow.h"
+
+
+const int ROWS = 2;
+const int COLUMNS = 3;
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ treeView = new QTreeView(this);
+ setCentralWidget(treeView);
+ standardModel = new QStandardItemModel ;
+
+ QList<QStandardItem *> preparedRow =prepareRow("first", "second", "third");
+ QStandardItem *item = standardModel->invisibleRootItem();
+ // adding a row to the invisible root item produces a root element
+ item->appendRow(preparedRow);
+
+ QList<QStandardItem *> secondRow =prepareRow("111", "222", "333");
+ // adding a row to an item starts a subtree
+ preparedRow.first()->appendRow(secondRow);
+
+ treeView->setModel(standardModel);
+ treeView->expandAll();
+}
+
+QList<QStandardItem *> MainWindow::prepareRow(const QString &first,
+ const QString &second,
+ const QString &third)
+{
+ QList<QStandardItem *> rowItems;
+ rowItems << new QStandardItem(first);
+ rowItems << new QStandardItem(second);
+ rowItems << new QStandardItem(third);
+ return rowItems;
+}
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/6_treeview/mainwindow.h b/examples/tutorials/modelview/6_treeview/mainwindow.h
new file mode 100755
index 0000000000..6398485cda
--- /dev/null
+++ b/examples/tutorials/modelview/6_treeview/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTreeView; //forward declarations
+class QStandardItemModel;
+class QStandardItem;
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTreeView *treeView;
+ QStandardItemModel *standardModel;
+ QList<QStandardItem *> prepareRow( const QString &first,
+ const QString &second,
+ const QString &third );
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/tutorials/modelview/7_selections/7_selections.pro b/examples/tutorials/modelview/7_selections/7_selections.pro
new file mode 100755
index 0000000000..5b01b0a190
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/7_selections.pro
@@ -0,0 +1,13 @@
+TARGET = mv_selections
+TEMPLATE = app
+SOURCES += main.cpp \
+ mainwindow.cpp
+HEADERS += mainwindow.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/7_selections
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS 7_selections.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview/7_selections
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/modelview/7_selections/main.cpp b/examples/tutorials/modelview/7_selections/main.cpp
new file mode 100755
index 0000000000..75246f7dc7
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+ return a.exec();
+}
diff --git a/examples/tutorials/modelview/7_selections/mainwindow.cpp b/examples/tutorials/modelview/7_selections/mainwindow.cpp
new file mode 100755
index 0000000000..3bd36d9df4
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/mainwindow.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [quoting modelview_a]
+#include <QTreeView>
+#include <QStandardItemModel>
+#include <QItemSelectionModel>
+#include "mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ treeView = new QTreeView(this);
+ setCentralWidget(treeView);
+ standardModel = new QStandardItemModel ;
+ QStandardItem *rootNode = standardModel->invisibleRootItem();
+
+
+ //defining a couple of items
+ QStandardItem *americaItem = new QStandardItem("America");
+ QStandardItem *mexicoItem = new QStandardItem("Canada");
+ QStandardItem *usaItem = new QStandardItem("USA");
+ QStandardItem *bostonItem = new QStandardItem("Boston");
+ QStandardItem *europeItem = new QStandardItem("Europe");
+ QStandardItem *italyItem = new QStandardItem("Italy");
+ QStandardItem *romeItem = new QStandardItem("Rome");
+ QStandardItem *veronaItem = new QStandardItem("Verona");
+
+ //building up the hierarchy
+ rootNode-> appendRow(americaItem);
+ rootNode-> appendRow(europeItem);
+ americaItem-> appendRow(mexicoItem);
+ americaItem-> appendRow(usaItem);
+ usaItem-> appendRow(bostonItem);
+ europeItem-> appendRow(italyItem);
+ italyItem-> appendRow(romeItem);
+ italyItem-> appendRow(veronaItem);
+
+ //register the model
+ treeView->setModel(standardModel);
+ treeView->expandAll();
+
+ //selection changes shall trigger a slot
+ QItemSelectionModel *selectionModel= treeView->selectionModel();
+ connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
+ this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));
+}
+//! [quoting modelview_a]
+
+//------------------------------------------------------------------------------------
+
+//! [quoting modelview_b]
+void MainWindow::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/)
+{
+ //get the text of the selected item
+ const QModelIndex index = treeView->selectionModel()->currentIndex();
+ QString selectedText = index.data(Qt::DisplayRole).toString();
+ //find out the hierarchy level of the selected item
+ int hierarchyLevel=1;
+ QModelIndex seekRoot = index;
+ while(seekRoot.parent() != QModelIndex())
+ {
+ seekRoot = seekRoot.parent();
+ hierarchyLevel++;
+ }
+ QString showString = QString("%1, Level %2").arg(selectedText)
+ .arg(hierarchyLevel);
+ setWindowTitle(showString);
+}
+//! [quoting modelview_b]
+
+
diff --git a/examples/tutorials/modelview/7_selections/mainwindow.h b/examples/tutorials/modelview/7_selections/mainwindow.h
new file mode 100755
index 0000000000..0a30dab085
--- /dev/null
+++ b/examples/tutorials/modelview/7_selections/mainwindow.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui/QMainWindow>
+
+QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code
+class QTreeView; //forward declarations
+class QStandardItemModel;
+class QItemSelection;
+QT_END_NAMESPACE
+
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+private:
+ QTreeView *treeView;
+ QStandardItemModel *standardModel;
+private slots:
+ void selectionChangedSlot(const QItemSelection & newSelection, const QItemSelection & oldSelection);
+public:
+ MainWindow(QWidget *parent = 0);
+};
+
+#endif // MAINWINDOW_H
diff --git a/examples/tutorials/modelview/modelview.pro b/examples/tutorials/modelview/modelview.pro
new file mode 100755
index 0000000000..45dc9c0612
--- /dev/null
+++ b/examples/tutorials/modelview/modelview.pro
@@ -0,0 +1,16 @@
+TEMPLATE = subdirs
+SUBDIRS = 1_readonly \
+ 2_formatting \
+ 3_changingmodel \
+ 4_headers \
+ 5_edit \
+ 6_treeview \
+ 7_selections
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS modelview.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/modelview
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/threads/clock/clock.pro b/examples/tutorials/threads/clock/clock.pro
new file mode 100755
index 0000000000..697c7bf7fc
--- /dev/null
+++ b/examples/tutorials/threads/clock/clock.pro
@@ -0,0 +1,14 @@
+CONFIG += console
+TEMPLATE = app
+SOURCES += main.cpp \
+ clockthread.cpp
+HEADERS += clockthread.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/clock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS clock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/clock
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/tutorials/threads/clock/clockthread.cpp b/examples/tutorials/threads/clock/clockthread.cpp
new file mode 100644
index 0000000000..01d3f1f697
--- /dev/null
+++ b/examples/tutorials/threads/clock/clockthread.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+#include "clockthread.h"
+
+ //This class starts another thread where it emits a signal for every new second.
+
+//! [1]
+// clock/clockthread.cpp
+void ClockThread::run()
+{
+ QTimer timer;
+ connect(&timer, SIGNAL(timeout()), this, SLOT(timerHit()), Qt::DirectConnection);
+ timer.setInterval(10);
+ timer.start(); // puts one event in the threads event queue
+ exec();
+ timer.stop();
+}
+
+void ClockThread::timerHit()
+{
+ QString newTime= QDateTime::currentDateTime().toString("ddd MMMM d yy, hh:mm:ss");
+ if(m_lastTime != newTime ){
+ m_lastTime = newTime;
+ emit sendTime(newTime) ;
+ }
+}
+//! [1]
diff --git a/examples/tutorials/threads/clock/clockthread.h b/examples/tutorials/threads/clock/clockthread.h
new file mode 100644
index 0000000000..966dbeaa73
--- /dev/null
+++ b/examples/tutorials/threads/clock/clockthread.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 CLOCKTHREAD_H
+#define CLOCKTHREAD_H
+
+#include <QString>
+#include <QThread>
+
+
+
+//! [1]
+// clock/clockthread.h
+class ClockThread : public QThread
+{
+ Q_OBJECT
+signals:
+ void sendTime(QString time);
+private:
+ void run();
+ QString m_lastTime;
+private slots:
+ void timerHit();
+
+};
+//! [1]
+#endif // CLOCKTHREAD_H \ No newline at end of file
diff --git a/examples/tutorials/threads/clock/main.cpp b/examples/tutorials/threads/clock/main.cpp
new file mode 100755
index 0000000000..a0f86d6bc7
--- /dev/null
+++ b/examples/tutorials/threads/clock/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+#include "clockthread.h"
+
+//A clock that does time formatting in another thread
+
+//! [1]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ // build gui
+ QWidget widget;
+ QLabel *label = new QLabel;
+ QHBoxLayout *layout = new QHBoxLayout(&widget);
+ layout->addWidget(label);
+ widget.setWindowTitle("clock");
+
+ //instantiate thread object
+ ClockThread clockThread;
+ QObject::connect(&clockThread, SIGNAL(sendTime(QString)), label, SLOT(setText(QString)), Qt::QueuedConnection);
+ clockThread.start();
+ widget.show();
+ app.exec();
+ clockThread.quit();
+ clockThread.wait();
+ return 0;
+}
+//! [1]
diff --git a/examples/tutorials/threads/helloconcurrent/helloconcurrent.cpp b/examples/tutorials/threads/helloconcurrent/helloconcurrent.cpp
new file mode 100755
index 0000000000..26ee2557a9
--- /dev/null
+++ b/examples/tutorials/threads/helloconcurrent/helloconcurrent.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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>
+/*
+ says hello from main thread and secondary thread using QtConcurrent
+*/
+
+//! [1]
+// helloconcurrent/main.cpp
+void hello()
+{
+ qDebug() << "Hello from thread " << QThread::currentThread();
+}
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ QFuture<void> future = QtConcurrent::run(hello);
+ qDebug() << "hello from GUI thread " << QThread::currentThread();
+ future.waitForFinished();
+ return 0;
+}
+//! [1]
diff --git a/examples/tutorials/threads/helloconcurrent/helloconcurrent.pro b/examples/tutorials/threads/helloconcurrent/helloconcurrent.pro
new file mode 100755
index 0000000000..817b5a809d
--- /dev/null
+++ b/examples/tutorials/threads/helloconcurrent/helloconcurrent.pro
@@ -0,0 +1,16 @@
+QT -= gui
+
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += helloconcurrent.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/helloconcurrent
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS helloconcurrent.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/helloconcurrent
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+
diff --git a/examples/tutorials/threads/hellothread/hellothread.cpp b/examples/tutorials/threads/hellothread/hellothread.cpp
new file mode 100755
index 0000000000..01cd0f5b3c
--- /dev/null
+++ b/examples/tutorials/threads/hellothread/hellothread.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QDebug>
+#include "hellothread.h"
+/*
+ * demonstrates use of QThread, says hello in another thread and terminates
+ */
+
+//! [1]
+// hellothread/hellothread.cpp
+void HelloThread::run()
+{
+ qDebug() << "hello from worker thread " << thread()->currentThreadId();
+}
+//! [1]
diff --git a/examples/tutorials/threads/hellothread/hellothread.h b/examples/tutorials/threads/hellothread/hellothread.h
new file mode 100755
index 0000000000..a3202c6396
--- /dev/null
+++ b/examples/tutorials/threads/hellothread/hellothread.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 HELLOTHREAD_H
+#define HELLOTHREAD_H
+
+#include <QThread>
+//! [1]
+// hellothread/hellothread.h
+class HelloThread : public QThread
+{
+ Q_OBJECT
+private:
+ void run();
+};
+//! [1]
+#endif // HELLOTHREAD_H
diff --git a/examples/tutorials/threads/hellothread/hellothread.pro b/examples/tutorials/threads/hellothread/hellothread.pro
new file mode 100755
index 0000000000..46a2709327
--- /dev/null
+++ b/examples/tutorials/threads/hellothread/hellothread.pro
@@ -0,0 +1,17 @@
+QT -= gui
+
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += main.cpp \
+ hellothread.cpp
+HEADERS += hellothread.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/hellothread
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellothread.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/hellothread
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/tutorials/threads/hellothread/main.cpp b/examples/tutorials/threads/hellothread/main.cpp
new file mode 100755
index 0000000000..9a548ea96a
--- /dev/null
+++ b/examples/tutorials/threads/hellothread/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "hellothread.h"
+
+//! [1]
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ HelloThread thread;
+ thread.start();
+ qDebug() << "hello from GUI thread " << app.thread()->currentThreadId();
+ thread.wait(); // do not exit before the thread is completed!
+ return 0;
+}
+//! [1]
diff --git a/examples/tutorials/threads/hellothreadpool/hellothreadpool.cpp b/examples/tutorials/threads/hellothreadpool/hellothreadpool.cpp
new file mode 100755
index 0000000000..30410a5570
--- /dev/null
+++ b/examples/tutorials/threads/hellothreadpool/hellothreadpool.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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>
+// A hello world program to demonstrate the use of the global thread pool
+
+//! [1]
+// hellothreadpool/main.cpp
+class Work : public QRunnable
+{
+public:
+ void run()
+ {
+ qDebug() << "Hello from thread " << QThread::currentThread();
+ }
+};
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ Work work;
+ work.setAutoDelete(false);
+ QThreadPool *threadPool = QThreadPool::globalInstance();
+ threadPool->start(&work);
+ qDebug() << "hello from GUI thread " << QThread::currentThread();
+ threadPool->waitForDone();
+ return 0;
+}
+//! [1]
diff --git a/examples/tutorials/threads/hellothreadpool/hellothreadpool.pro b/examples/tutorials/threads/hellothreadpool/hellothreadpool.pro
new file mode 100755
index 0000000000..d1f3efd5b8
--- /dev/null
+++ b/examples/tutorials/threads/hellothreadpool/hellothreadpool.pro
@@ -0,0 +1,17 @@
+QT -= gui
+
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += hellothreadpool.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/hellothreadpool
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS hellothreadpool.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/hellothreadpool
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+
+
diff --git a/examples/tutorials/threads/movedobject/main.cpp b/examples/tutorials/threads/movedobject/main.cpp
new file mode 100755
index 0000000000..a244316689
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/main.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "workerobject.h"
+#include "thread.h"
+
+/*
+ * moves a class derived from QObject (WorkerObject) to another thread
+ * and calls methods over thread boundaries.
+ */
+
+//![1]
+// movedobject/main.cpp
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ Thread thread;
+ qDebug() << "main thread ID: " << app.thread()->currentThreadId();
+ WorkerObject *worker = new WorkerObject;
+ thread.launchWorker(worker);
+ QMetaObject::invokeMethod(worker, "doWork", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(worker, "startPolling", Qt::QueuedConnection, Q_ARG(int, 500));
+ //let application produce output for 3 seconds and quit
+ QTimer::singleShot(3000, &app, SLOT(quit()));
+ app.exec();
+ thread.stop();
+ thread.wait();
+ delete worker;
+ return 0;
+}
+//![1]
diff --git a/examples/tutorials/threads/movedobject/movedobject.pro b/examples/tutorials/threads/movedobject/movedobject.pro
new file mode 100755
index 0000000000..4b5a1ce159
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/movedobject.pro
@@ -0,0 +1,18 @@
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += main.cpp \
+ workerobject.cpp \
+ thread.cpp
+
+HEADERS += \
+ workerobject.h \
+ thread.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/movedobject
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS movedobject.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/threads/movedobject
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/tutorials/threads/movedobject/thread.cpp b/examples/tutorials/threads/movedobject/thread.cpp
new file mode 100644
index 0000000000..6dfe8ff159
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/thread.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "thread.h"
+
+/*
+ * QThread derived class with additional capability to move a QObject to the
+ * new thread, to stop the thread and move the QObject back to the thread where
+ *it came from.
+ */
+
+Thread::Thread( QObject *parent)
+ : QThread (parent)
+{
+ //we need a class that receives signals from other threads and emits a signal in response
+ shutDownHelper=new QSignalMapper;
+ shutDownHelper->setMapping(this,0);
+ connect(this, SIGNAL(started()), this, SLOT(setReadyStatus() ), Qt::DirectConnection);
+ connect(this, SIGNAL(aboutToStop()), shutDownHelper, SLOT(map()) );
+}
+
+//------------------------------------------------------
+Thread::~Thread()
+{
+ delete shutDownHelper;
+}
+
+//------------------------------------------------------
+// starts thread, moves worker to this thread and blocks
+void Thread::launchWorker(QObject *worker)
+{
+ worker = worker;
+ start();
+ int i=0;
+ worker->moveToThread(this);
+ shutDownHelper->moveToThread(this);
+ connect(shutDownHelper, SIGNAL(mapped(int) ), this, SLOT(stopExecutor()), Qt::DirectConnection );
+ mutex.lock();
+ waitCondition.wait(&mutex);
+}
+
+//------------------------------------------------------
+// puts a command to stop processing in the event queue of worker thread
+void Thread::stop()
+{
+ emit aboutToStop();
+}
+
+//------------------------------------------------------
+
+// methods above this line should be called in gui thread context
+// methods below this line are private and will be run in secondary thread context
+
+//------------------------------------------------------
+void Thread::stopExecutor() //secondary thread context
+{
+ exit();
+}
+
+//------------------------------------------------------
+void Thread::setReadyStatus()
+{
+ waitCondition.wakeAll();
+}
diff --git a/examples/tutorials/threads/movedobject/thread.h b/examples/tutorials/threads/movedobject/thread.h
new file mode 100644
index 0000000000..e941e99123
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/thread.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 THREAD_H
+#define THREAD_H
+
+#include <QtCore>
+
+class Thread :public QThread
+{
+ Q_OBJECT
+public:
+ Thread( QObject *parent=0);
+ ~Thread();
+ void stop();
+ void launchWorker(QObject *worker);
+private:
+ QObject *worker;
+ QSignalMapper *shutDownHelper;
+ QWaitCondition waitCondition;
+ QMutex mutex;
+private slots:
+ void stopExecutor();
+ void setReadyStatus();
+signals:
+ void aboutToStop();
+};
+
+#endif // THREAD_H
diff --git a/examples/tutorials/threads/movedobject/workerobject.cpp b/examples/tutorials/threads/movedobject/workerobject.cpp
new file mode 100644
index 0000000000..819da20bc2
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/workerobject.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "workerobject.h"
+
+/*
+ * represents an object that lives in another thread where it polls a resource
+ * and communicates with the gui thread
+ */
+
+WorkerObject::WorkerObject(QObject *parent)
+ : QObject(parent)
+{
+ timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(poll()));
+}
+
+//---------------------------------------------------------------
+void WorkerObject::doWork()
+{
+
+ qDebug() << "doing work in thread " << thread()->currentThreadId() ;
+}
+
+//---------------------------------------------------------------
+WorkerObject::~WorkerObject()
+{
+ qDebug() << "destruction WorkerObject in thread " << thread()->currentThreadId();
+}
+
+//---------------------------------------------------------------
+void WorkerObject::startPolling(int milliseconds)
+{
+ count=0;
+ timer->start(milliseconds);
+}
+
+//---------------------------------------------------------------
+void WorkerObject::stopPolling()
+{
+ timer->stop();
+}
+
+//---------------------------------------------------------------
+void WorkerObject::poll()
+{
+ qDebug() << QString("timer hit %1").arg(count);
+ count++;
+}
+
diff --git a/examples/tutorials/threads/movedobject/workerobject.h b/examples/tutorials/threads/movedobject/workerobject.h
new file mode 100644
index 0000000000..09a827c4da
--- /dev/null
+++ b/examples/tutorials/threads/movedobject/workerobject.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 WORKEROBJECT_H
+#define WORKEROBJECT_H
+
+#include <QtCore>
+
+class WorkerObject : public QObject
+{
+ Q_OBJECT
+public:
+ explicit WorkerObject(QObject *parent = 0);
+ ~WorkerObject();
+public slots:
+ void doWork();
+ void startPolling(int milliseconds);
+ void stopPolling();
+private slots:
+ void poll();
+private:
+ QTimer *timer;
+ int count;
+};
+
+#endif // WORKEROBJECT_H
diff --git a/examples/tutorials/threads/threads.pro b/examples/tutorials/threads/threads.pro
new file mode 100644
index 0000000000..d737513567
--- /dev/null
+++ b/examples/tutorials/threads/threads.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+
+SUBDIRS = hellothread \
+ hellothreadpool \
+ helloconcurrent \
+ clock \
+ movedobject
+
diff --git a/examples/tutorials/tutorials.pro b/examples/tutorials/tutorials.pro
new file mode 100644
index 0000000000..cb57002082
--- /dev/null
+++ b/examples/tutorials/tutorials.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS += addressbook-fr threads addressbook widgets modelview gettingStarted
diff --git a/examples/tutorials/widgets/childwidget/childwidget.pro b/examples/tutorials/widgets/childwidget/childwidget.pro
new file mode 100644
index 0000000000..ea319ad282
--- /dev/null
+++ b/examples/tutorials/widgets/childwidget/childwidget.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/childwidget
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS childwidget.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/childwidget
+INSTALLS += target sources
diff --git a/examples/tutorials/widgets/childwidget/main.cpp b/examples/tutorials/widgets/childwidget/main.cpp
new file mode 100644
index 0000000000..15eda9f121
--- /dev/null
+++ b/examples/tutorials/widgets/childwidget/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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$
+**
+****************************************************************************/
+
+//! [main program]
+#include <QtGui>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QWidget window;
+ window.resize(320, 240);
+ window.setWindowTitle(QApplication::translate("childwidget", "Child widget"));
+ window.show();
+
+//! [create, position and show]
+ QPushButton *button = new QPushButton(
+ QApplication::translate("childwidget", "Press me"), &window);
+ button->move(100, 100);
+ button->show();
+//! [create, position and show]
+ return app.exec();
+}
+//! [main program]
diff --git a/examples/tutorials/widgets/nestedlayouts/main.cpp b/examples/tutorials/widgets/nestedlayouts/main.cpp
new file mode 100644
index 0000000000..40c63ab1fd
--- /dev/null
+++ b/examples/tutorials/widgets/nestedlayouts/main.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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$
+**
+****************************************************************************/
+
+//! [main program]
+//! [first part]
+#include <QtGui>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QWidget window;
+
+ QLabel *queryLabel = new QLabel(
+ QApplication::translate("nestedlayouts", "Query:"));
+ QLineEdit *queryEdit = new QLineEdit();
+ QTableView *resultView = new QTableView();
+
+ QHBoxLayout *queryLayout = new QHBoxLayout();
+ queryLayout->addWidget(queryLabel);
+ queryLayout->addWidget(queryEdit);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout();
+ mainLayout->addLayout(queryLayout);
+ mainLayout->addWidget(resultView);
+ window.setLayout(mainLayout);
+
+ // Set up the model and configure the view...
+//! [first part]
+
+//! [set up the model]
+ QStandardItemModel model;
+ model.setHorizontalHeaderLabels(
+ QStringList() << QApplication::translate("nestedlayouts", "Name")
+ << QApplication::translate("nestedlayouts", "Office"));
+
+ QList<QStringList> rows = QList<QStringList>()
+ << (QStringList() << "Verne Nilsen" << "123")
+ << (QStringList() << "Carlos Tang" << "77")
+ << (QStringList() << "Bronwyn Hawcroft" << "119")
+ << (QStringList() << "Alessandro Hanssen" << "32")
+ << (QStringList() << "Andrew John Bakken" << "54")
+ << (QStringList() << "Vanessa Weatherley" << "85")
+ << (QStringList() << "Rebecca Dickens" << "17")
+ << (QStringList() << "David Bradley" << "42")
+ << (QStringList() << "Knut Walters" << "25")
+ << (QStringList() << "Andrea Jones" << "34");
+
+ foreach (QStringList row, rows) {
+ QList<QStandardItem *> items;
+ foreach (QString text, row)
+ items.append(new QStandardItem(text));
+ model.appendRow(items);
+ }
+
+ resultView->setModel(&model);
+ resultView->verticalHeader()->hide();
+ resultView->horizontalHeader()->setStretchLastSection(true);
+//! [set up the model]
+//! [last part]
+ window.setWindowTitle(
+ QApplication::translate("nestedlayouts", "Nested layouts"));
+ window.show();
+ return app.exec();
+}
+//! [last part]
+//! [main program]
diff --git a/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro b/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro
new file mode 100644
index 0000000000..cb27f9ecc4
--- /dev/null
+++ b/examples/tutorials/widgets/nestedlayouts/nestedlayouts.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/nestedlayouts
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS nestedlayouts.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/nestedlayouts
+INSTALLS += target sources
diff --git a/examples/tutorials/widgets/toplevel/main.cpp b/examples/tutorials/widgets/toplevel/main.cpp
new file mode 100644
index 0000000000..f7baf0610e
--- /dev/null
+++ b/examples/tutorials/widgets/toplevel/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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$
+**
+****************************************************************************/
+
+//! [main program]
+#include <QtGui>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+//! [create, resize and show]
+ QWidget window;
+ window.resize(320, 240);
+ window.show();
+//! [create, resize and show]
+ window.setWindowTitle(
+ QApplication::translate("toplevel", "Top-level widget"));
+ return app.exec();
+}
+//! [main program]
diff --git a/examples/tutorials/widgets/toplevel/toplevel.pro b/examples/tutorials/widgets/toplevel/toplevel.pro
new file mode 100644
index 0000000000..b83ccfaf70
--- /dev/null
+++ b/examples/tutorials/widgets/toplevel/toplevel.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/toplevel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS toplevel.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/toplevel
+INSTALLS += target sources
diff --git a/examples/tutorials/widgets/widgets.pro b/examples/tutorials/widgets/widgets.pro
new file mode 100644
index 0000000000..c03d43d7c2
--- /dev/null
+++ b/examples/tutorials/widgets/widgets.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+SUBDIRS = toplevel childwidget windowlayout nestedlayouts
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS widgets.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets
+INSTALLS += target sources
diff --git a/examples/tutorials/widgets/windowlayout/main.cpp b/examples/tutorials/widgets/windowlayout/main.cpp
new file mode 100644
index 0000000000..ada9ae7380
--- /dev/null
+++ b/examples/tutorials/widgets/windowlayout/main.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the 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$
+**
+****************************************************************************/
+
+//! [main program]
+#include <QtGui>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QWidget window;
+//! [create, lay out widgets and show]
+ QLabel *label = new QLabel(QApplication::translate("windowlayout", "Name:"));
+ QLineEdit *lineEdit = new QLineEdit();
+
+ QHBoxLayout *layout = new QHBoxLayout();
+ layout->addWidget(label);
+ layout->addWidget(lineEdit);
+ window.setLayout(layout);
+//! [create, lay out widgets and show]
+ window.setWindowTitle(
+ QApplication::translate("windowlayout", "Window layout"));
+ window.show();
+ return app.exec();
+}
+//! [main program]
diff --git a/examples/tutorials/widgets/windowlayout/windowlayout.pro b/examples/tutorials/widgets/windowlayout/windowlayout.pro
new file mode 100644
index 0000000000..f8b55ba214
--- /dev/null
+++ b/examples/tutorials/widgets/windowlayout/windowlayout.pro
@@ -0,0 +1,7 @@
+SOURCES = main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/windowlayout
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS windowlayout.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/tutorials/widgets/windowlayout
+INSTALLS += target sources
diff --git a/examples/uitools/multipleinheritance/calculatorform.cpp b/examples/uitools/multipleinheritance/calculatorform.cpp
new file mode 100644
index 0000000000..2963db356a
--- /dev/null
+++ b/examples/uitools/multipleinheritance/calculatorform.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 <QtGui>
+#include "calculatorform.h"
+
+
+//! [0]
+CalculatorForm::CalculatorForm(QWidget *parent)
+ : QWidget(parent)
+{
+ setupUi(this);
+}
+//! [0]
+
+//! [1]
+void CalculatorForm::on_inputSpinBox1_valueChanged(int value)
+{
+ outputWidget->setText(QString::number(value + inputSpinBox2->value()));
+}
+//! [1]
+
+//! [2]
+void CalculatorForm::on_inputSpinBox2_valueChanged(int value)
+{
+ outputWidget->setText(QString::number(value + inputSpinBox1->value()));
+}
+//! [2]
diff --git a/examples/uitools/multipleinheritance/calculatorform.h b/examples/uitools/multipleinheritance/calculatorform.h
new file mode 100644
index 0000000000..9b8c8880bf
--- /dev/null
+++ b/examples/uitools/multipleinheritance/calculatorform.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALCULATORFORM_H
+#define CALCULATORFORM_H
+
+//! [0]
+#include "ui_calculatorform.h"
+//! [0]
+
+//! [1]
+class CalculatorForm : public QWidget, private Ui::CalculatorForm
+{
+ Q_OBJECT
+
+public:
+ CalculatorForm(QWidget *parent = 0);
+
+private slots:
+ void on_inputSpinBox1_valueChanged(int value);
+ void on_inputSpinBox2_valueChanged(int value);
+};
+//! [1]
+
+#endif
diff --git a/examples/uitools/multipleinheritance/calculatorform.ui b/examples/uitools/multipleinheritance/calculatorform.ui
new file mode 100644
index 0000000000..dda0e62ddd
--- /dev/null
+++ b/examples/uitools/multipleinheritance/calculatorform.ui
@@ -0,0 +1,303 @@
+<ui version="4.0" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>CalculatorForm</class>
+ <widget class="QWidget" name="CalculatorForm" >
+ <property name="objectName" >
+ <string notr="true" >CalculatorForm</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>276</width>
+ <height>98</height>
+ </rect>
+ </property>
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle" >
+ <string>Calculator Builder</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="objectName" >
+ <string notr="true" />
+ </property>
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="0" column="0" >
+ <layout class="QHBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" />
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" />
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="objectName" >
+ <string notr="true" >label</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>1</y>
+ <width>45</width>
+ <height>19</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Input 1</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="inputSpinBox1" >
+ <property name="objectName" >
+ <string notr="true" >inputSpinBox1</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>26</y>
+ <width>45</width>
+ <height>25</height>
+ </rect>
+ </property>
+ <property name="mouseTracking" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3" >
+ <property name="objectName" >
+ <string notr="true" >label_3</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>54</x>
+ <y>1</y>
+ <width>7</width>
+ <height>52</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>+</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" />
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_2" >
+ <property name="objectName" >
+ <string notr="true" >label_2</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>1</y>
+ <width>45</width>
+ <height>19</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Input 2</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="inputSpinBox2" >
+ <property name="objectName" >
+ <string notr="true" >inputSpinBox2</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>26</y>
+ <width>45</width>
+ <height>25</height>
+ </rect>
+ </property>
+ <property name="mouseTracking" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3_2" >
+ <property name="objectName" >
+ <string notr="true" >label_3_2</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>120</x>
+ <y>1</y>
+ <width>7</width>
+ <height>52</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>=</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <property name="objectName" >
+ <string notr="true" />
+ </property>
+ <property name="margin" >
+ <number>1</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label_2_2_2" >
+ <property name="objectName" >
+ <string notr="true" >label_2_2_2</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>1</y>
+ <width>37</width>
+ <height>17</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Output</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="outputWidget" >
+ <property name="objectName" >
+ <string notr="true" >outputWidget</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>1</x>
+ <y>24</y>
+ <width>37</width>
+ <height>27</height>
+ </rect>
+ </property>
+ <property name="frameShape" >
+ <enum>QFrame::Box</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <property name="text" >
+ <string>0</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" >
+ <spacer>
+ <property name="objectName" >
+ <string notr="true" >verticalSpacer</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>85</x>
+ <y>69</y>
+ <width>20</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="1" >
+ <spacer>
+ <property name="objectName" >
+ <string notr="true" >horizontalSpacer</string>
+ </property>
+ <property name="geometry" >
+ <rect>
+ <x>188</x>
+ <y>26</y>
+ <width>79</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/uitools/multipleinheritance/main.cpp b/examples/uitools/multipleinheritance/main.cpp
new file mode 100644
index 0000000000..f61c92c1c4
--- /dev/null
+++ b/examples/uitools/multipleinheritance/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "calculatorform.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ CalculatorForm calculator;
+ calculator.show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/uitools/multipleinheritance/multipleinheritance.pro b/examples/uitools/multipleinheritance/multipleinheritance.pro
new file mode 100644
index 0000000000..d6aa6c3fec
--- /dev/null
+++ b/examples/uitools/multipleinheritance/multipleinheritance.pro
@@ -0,0 +1,16 @@
+#! [0]
+SOURCES = calculatorform.cpp main.cpp
+HEADERS = calculatorform.h
+FORMS = calculatorform.ui
+#! [0]
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/multipleinheritance
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/multipleinheritance
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000D7C1
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/uitools/textfinder/forms/input.txt b/examples/uitools/textfinder/forms/input.txt
new file mode 100644
index 0000000000..29dfe5d6c6
--- /dev/null
+++ b/examples/uitools/textfinder/forms/input.txt
@@ -0,0 +1,9 @@
+These forms are processed at run-time to produce dynamically-generated user interfaces.
+In order to generate a form at run-time, a resource file containing a UI file is needed.
+Applications that use the form handling classes need to be configured to be built against
+the QtUiTools module. This is done by including the following declaration in a qmake project
+file to ensure that the application is compiled and linked appropriately. A form loader object,
+provided by the QUiLoader class, is used to construct the user interface. This user interface
+can be retrieved from any QIODevice; for example, a QFile object can be used to obtain a form
+stored in a project's resources. The QUiLoader::load() function takes the user interface
+description contained in the file and constructs the form widget. \ No newline at end of file
diff --git a/examples/uitools/textfinder/forms/textfinder.ui b/examples/uitools/textfinder/forms/textfinder.ui
new file mode 100644
index 0000000000..af05192dbd
--- /dev/null
+++ b/examples/uitools/textfinder/forms/textfinder.ui
@@ -0,0 +1,89 @@
+<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>158</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Find Text</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="lineEdit" />
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="searchLabel" >
+ <property name="text" >
+ <string>&amp;Keyword:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>lineEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QPushButton" name="findButton" >
+ <property name="text" >
+ <string>&amp;Find</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="textEdit" />
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>lineEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>findButton</receiver>
+ <slot>animateClick()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>261</x>
+ <y>17</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>320</x>
+ <y>17</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/uitools/textfinder/main.cpp b/examples/uitools/textfinder/main.cpp
new file mode 100644
index 0000000000..2fe9b715d1
--- /dev/null
+++ b/examples/uitools/textfinder/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "textfinder.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(textfinder);
+ QApplication app(argc, argv);
+
+ TextFinder *textFinder = new TextFinder;
+ textFinder->show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/uitools/textfinder/textfinder.cpp b/examples/uitools/textfinder/textfinder.cpp
new file mode 100644
index 0000000000..0a69d5e2dd
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.cpp
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtUiTools>
+#include <QtGui>
+#include "textfinder.h"
+
+//! [0]
+TextFinder::TextFinder(QWidget *parent)
+ : QWidget(parent)
+{
+ QWidget *formWidget = loadUiFile();
+
+//! [1]
+ ui_findButton = findChild<QPushButton*>("findButton");
+ ui_textEdit = findChild<QTextEdit*>("textEdit");
+ ui_lineEdit = findChild<QLineEdit*>("lineEdit");
+//! [0] //! [1]
+
+//! [2]
+ QMetaObject::connectSlotsByName(this);
+//! [2]
+
+//! [3a]
+ loadTextFile();
+//! [3a]
+
+//! [3b]
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(formWidget);
+ setLayout(layout);
+//! [3b]
+
+//! [3c]
+ setWindowTitle(tr("Text Finder"));
+ isFirstTime = true;
+}
+//! [3c]
+
+//! [4]
+QWidget* TextFinder::loadUiFile()
+{
+ QUiLoader loader;
+
+ QFile file(":/forms/textfinder.ui");
+ file.open(QFile::ReadOnly);
+
+ QWidget *formWidget = loader.load(&file, this);
+ file.close();
+
+ return formWidget;
+}
+//! [4]
+
+//! [5]
+void TextFinder::loadTextFile()
+{
+ QFile inputFile(":/forms/input.txt");
+ inputFile.open(QIODevice::ReadOnly);
+ QTextStream in(&inputFile);
+ QString line = in.readAll();
+ inputFile.close();
+
+ ui_textEdit->append(line);
+ ui_textEdit->setUndoRedoEnabled(false);
+ ui_textEdit->setUndoRedoEnabled(true);
+}
+//! [5]
+
+//! [6] //! [7]
+void TextFinder::on_findButton_clicked()
+{
+ QString searchString = ui_lineEdit->text();
+ QTextDocument *document = ui_textEdit->document();
+
+ bool found = false;
+
+ if (isFirstTime == false)
+ document->undo();
+
+ if (searchString.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Search Field"),
+ "The search field is empty. Please enter a word and click Find.");
+ } else {
+
+ QTextCursor highlightCursor(document);
+ QTextCursor cursor(document);
+
+ cursor.beginEditBlock();
+//! [6]
+
+ QTextCharFormat plainFormat(highlightCursor.charFormat());
+ QTextCharFormat colorFormat = plainFormat;
+ colorFormat.setForeground(Qt::red);
+
+ while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
+ highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);
+
+ if (!highlightCursor.isNull()) {
+ found = true;
+ highlightCursor.movePosition(QTextCursor::WordRight,
+ QTextCursor::KeepAnchor);
+ highlightCursor.mergeCharFormat(colorFormat);
+ }
+ }
+
+//! [8]
+ cursor.endEditBlock();
+//! [7] //! [9]
+ isFirstTime = false;
+
+ if (found == false) {
+ QMessageBox::information(this, tr("Word Not Found"),
+ "Sorry, the word cannot be found.");
+ }
+ }
+}
+//! [8] //! [9]
diff --git a/examples/uitools/textfinder/textfinder.h b/examples/uitools/textfinder/textfinder.h
new file mode 100644
index 0000000000..c3cd030cb2
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTFINDER_H
+#define TEXTFINDER_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QTextEdit;
+class QLineEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class TextFinder : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TextFinder(QWidget *parent = 0);
+
+private slots:
+ void on_findButton_clicked();
+
+private:
+ QWidget* loadUiFile();
+ void loadTextFile();
+
+ QPushButton *ui_findButton;
+ QTextEdit *ui_textEdit;
+ QLineEdit *ui_lineEdit;
+ bool isFirstTime;
+};
+//! [0]
+
+#endif
diff --git a/examples/uitools/textfinder/textfinder.pro b/examples/uitools/textfinder/textfinder.pro
new file mode 100644
index 0000000000..6ec523b37b
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.pro
@@ -0,0 +1,12 @@
+CONFIG += uitools
+HEADERS = textfinder.h
+RESOURCES = textfinder.qrc
+SOURCES = textfinder.cpp main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/textfinder
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro forms
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/textfinder
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/uitools/textfinder/textfinder.qrc b/examples/uitools/textfinder/textfinder.qrc
new file mode 100644
index 0000000000..a4cea8a77d
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>forms/textfinder.ui</file>
+ <file>forms/input.txt</file>
+</qresource>
+</RCC> \ No newline at end of file
diff --git a/examples/uitools/uitools.pro b/examples/uitools/uitools.pro
new file mode 100644
index 0000000000..5c3f3de111
--- /dev/null
+++ b/examples/uitools/uitools.pro
@@ -0,0 +1,12 @@
+TEMPLATE = subdirs
+SUBDIRS = multipleinheritance
+
+!wince*:!symbian:contains(QT_BUILD_PARTS, tools): SUBDIRS += textfinder
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS uitools.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/webkit/webkit-guide/_copyright.txt b/examples/webkit/webkit-guide/_copyright.txt
new file mode 100644
index 0000000000..e545ac3d90
--- /dev/null
+++ b/examples/webkit/webkit-guide/_copyright.txt
@@ -0,0 +1,40 @@
+<!--
+
+This file is part of _PACKAGE_NAME_
+
+Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+\1
diff --git a/examples/webkit/webkit-guide/_image_assets.htm b/examples/webkit/webkit-guide/_image_assets.htm
new file mode 100644
index 0000000000..5c3f3a076f
--- /dev/null
+++ b/examples/webkit/webkit-guide/_image_assets.htm
@@ -0,0 +1,331 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<title>image assets</title>
+
+<style>
+img { max-height: 72px; }
+</style>
+
+</head>
+<body>
+<h1>image assets</h1>
+
+Notes:
+
+<ul>
+
+<li>Some of these may be redundant; feel free to merge
+
+<li>Feel free to rename files, but give me before & after list of filenames so I can reflect the change
+
+<li>use neutral grayscale if possible
+
+<li>use PNG file format if possible
+
+<li>I plan to cut new set of generic icons
+(e.g., <a href="anim_skew.htm">HERE</a> to be white text on darkish
+gray, probably #777777)
+
+<li>No more need for online/offline indicators (red/green circles) for
+this draft.
+
+</ul>
+
+<table border="1" width="100%">
+
+<tr>
+<th>FILENAME</th>
+<th>IMAGE (thumbnail & link)</th>
+<th>USED ON PAGE</th>
+<th>DESCRIPTION</th>
+</tr>
+
+<tr>
+<td>icon_dismiss.png,<br/>icon_dismiss_x22.png</td>
+<td>
+<a target="elsewhere" href="img/icon_dismiss.png"><img src="img/icon_dismiss.png"/></a>
+<a target="elsewhere" href="img/icon_dismiss_x22.png"><img src="img/icon_dismiss_x22.png"/></a>
+</td>
+<td>
+<a target="elsewhere" href="anim_skew.htm">HERE</a>
+<a target="elsewhere" href="storage.htm">HERE</a>
+<a target="elsewhere" href="css3_text-overflow.htm">HERE</a>
+<a target="elsewhere" href="layout_tbl-keyhole.htm">HERE</a>
+</td>
+<td>Dismiss panel or listed item</td>
+</tr>
+
+<tr>
+<td>icon_expand-nav.png</td>
+<td><a target="elsewhere" href="img/icon_expand-nav.png"><img src="img/icon_expand-nav.png"/></a></td>
+<td><a target="elsewhere" href="anim_accord.htm">HERE</a></td>
+<td>expand complex set of navigation options</td>
+</tr>
+
+<tr>
+<td>icon_nav-up.png</td>
+<td><a target="elsewhere" href="img/icon_nav-up.png"><img src="img/icon_nav-up.png"/></a></td>
+<td><a target="elsewhere" href="layout_tbl-keyhole.htm">HERE</a></td>
+<td>navigate within listings (up arrow also serves as down arrow using rotate transform)</td>
+</tr>
+
+<tr>
+<td>icon_drill-up.png,<br/>icon_drill-up_x32.png</td>
+<td>
+<a target="elsewhere" href="img/icon_drill-up.png"><img src="img/icon_drill-up.png"/></a>
+<a target="elsewhere" href="img/icon_drill-up_x32.png"><img src="img/icon_drill-up_x32.png"/></a>
+</td>
+<td><a target="elsewhere" href="anim_slide1.htm">HERE</a></td>
+<td>navigate up one level within sliding drilldown UI</td>
+</tr>
+
+<tr>
+<td>icon_drill-down.png,<br/>icon_drill-down_x32.png</td>
+<td>
+<a target="elsewhere" href="img/icon_drill-down.png"><img src="img/icon_drill-down.png"/></a>
+<a target="elsewhere" href="img/icon_drill-down_x32.png"><img src="img/icon_drill-down_x32.png"/></a>
+</td>
+<td><a target="elsewhere" href="anim_slide1.htm">HERE</a></td>
+<td>navigate down one level within sliding drilldown UI</td>
+</tr>
+
+<tr>
+<td>icon_scroll-left.png</td>
+<td><a target="elsewhere" href="img/icon_scroll-left.png"><img src="img/icon_scroll-left.png"/></a></td>
+<td><a target="elsewhere" href="css3_scroll.htm">HERE</a></td>
+<td>custom horizontal scroll button</td>
+</tr>
+
+<tr>
+<td>icon_scroll-right.png</td>
+<td><a target="elsewhere" href="img/icon_scroll-right.png"><img src="img/icon_scroll-right.png"/></a></td>
+<td><a target="elsewhere" href="css3_scroll.htm">HERE</a></td>
+<td>custom horizontal scroll button</td>
+</tr>
+
+<tr>
+<td>icon_head-expanded.png,<br/>icon_head-expanded_x13.png</td>
+<td>
+<a target="elsewhere" href="img/icon_head-expanded.png"><img src="img/icon_head-expanded.png"/></a>
+<a target="elsewhere" href="img/icon_head-expanded_x13.png"><img src="img/icon_head-expanded_x13.png"/></a>
+</td>
+<td><a target="elsewhere" href="anim_accord.htm">HERE</a>
+<a target="elsewhere" href="css3_backgrounds.htm">HERE</a></td>
+<td>marks accordion heading expanded state</td>
+</tr>
+
+<tr>
+<td>icon_head-collapsed.png,<br/>icon_head-collapsed_x13.png</td>
+<td>
+<a target="elsewhere" href="img/icon_head-collapsed.png"><img src="img/icon_head-collapsed.png"/></a>
+<a target="elsewhere" href="img/icon_head-collapsed_x13.png"><img src="img/icon_head-collapsed_x13.png"/></a>
+</td>
+<td><a target="elsewhere" href="anim_accord.htm">HERE</a>
+<a target="elsewhere" href="css3_backgrounds.htm">HERE</a></td>
+<td>marks accordion heading collapsed state</td>
+</tr>
+
+<tr>
+<td>icon_info.png,<br/>icon_info_x24.png</td>
+<td>
+<a target="elsewhere" href="img/icon_info.png"><img src="img/icon_info.png"/></a>
+<a target="elsewhere" href="img/icon_info_x24.png"><img src="img/icon_info_x24.png"/></a>
+</td>
+<td><a target="elsewhere" href="storage.htm">HERE</a></td>
+<td>link to panel specifying user preferences</td>
+</tr>
+
+<tr>
+<td>icon_list-all.png,<br/>icon_list-all_circ.png</td>
+<td>
+<a target="elsewhere" href="img/icon_list-all.png"><img src="img/icon_list-all.png"/></a>
+<a target="elsewhere" href="img/icon_list-all_circ.png"><img src="img/icon_list-all_circ.png"/></a>
+</td>
+<td><a target="elsewhere" href="anim_skew.htm">HERE</a></td>
+<td>within UI listing items users can filter by category, this indicates LIST ALL ITEMS</td>
+</tr>
+
+<tr>
+<td>gradient.jpg</td>
+<td><a target="elsewhere" href="img/gradient.jpg"><img src="img/gradient.jpg"/></a></td>
+<td><a target="elsewhere" href="css3_backgrounds.htm">HERE</a></td>
+<td>serves as background for expanded accordion heads (demonstrates CSS's >1 background image feature)</td>
+</tr>
+
+<tr>
+<td>border-frame.png</td>
+<td><a target="elsewhere" href="img/border-frame.png"><img src="img/border-frame.png"/></a></td>
+<td><a target="elsewhere" href="css3_border-img.htm">HERE</a></td>
+<td>border around chunk of text (got this from Wei Lu's sample; simply demo's this feature)</td>
+</tr>
+
+<tr>
+<td>mask.png</td>
+<td><a target="elsewhere" href="img/mask.png"><img src="img/mask.png"/></a></td>
+<td><a target="elsewhere" href="css3_mask-img.htm">HERE</a></td>
+<td>Used as a gradient to mask an image; think I got this one from <a href="http://webkit.org/blog/181/css-masks/">webkit.org</a></td>
+</tr>
+
+<tr>
+<td>icon_check.png,<br/>icon_check_x24green.png</td>
+<td>
+<a target="elsewhere" href="img/icon_check.png"><img src="img/icon_check.png"/></a>
+<a target="elsewhere" href="img/icon_check_x24green.png"><img src="img/icon_check_x24green.png"/></a>
+</td>
+<td><a target="elsewhere" href="form_tapper.htm">HERE</a></td>
+<td>This is not available as a separate file; it's specified within
+CSS using the "data:" URL scheme. It indicates radio/checkbox
+selection state within tappable UI; keep green if possible to match
+border</td>
+</tr>
+
+<tr>
+<th colspan="4">FILE FORMATS</th>
+<tr>
+
+<tr>
+<td>icon_link-sms.png</td>
+<td><a target="elsewhere" href="img/icon_link-sms.png"><img src="img/icon_link-sms.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>provides visual hint marking context of hyperlink, in this case a link to initiate an instant message</td>
+</tr>
+
+<tr>
+<td>icon_link-tel.png</td>
+<td><a target="elsewhere" href="img/icon_link-tel.png"><img src="img/icon_link-tel.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to make phone call</td>
+</tr>
+
+<tr>
+<td>icon_link-xls.png</td>
+<td><a target="elsewhere" href="img/icon_link-xls.png"><img src="img/icon_link-xls.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to excel file</td>
+</tr>
+
+<tr>
+<td>icon_link-doc.png</td>
+<td><a target="elsewhere" href="img/icon_link-doc.png"><img src="img/icon_link-doc.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to MS Word file</td>
+</tr>
+
+<tr>
+<td>icon_link-email.png</td>
+<td><a target="elsewhere" href="img/icon_link-email.png"><img src="img/icon_link-email.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...email link</td>
+</tr>
+
+<tr>
+<td>icon_link-external.png</td>
+<td><a target="elsewhere" href="img/icon_link-external.png"><img src="img/icon_link-external.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to web page external to current site</td>
+</tr>
+
+<tr>
+<td>icon_link-pdf.png</td>
+<td><a target="elsewhere" href="img/icon_link-pdf.png"><img src="img/icon_link-pdf.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...loink to PDF file</td>
+</tr>
+
+<tr>
+<td>icon_link-ppt.png</td>
+<td><a target="elsewhere" href="img/icon_link-ppt.png"><img src="img/icon_link-ppt.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to PowerPoint file</td>
+</tr>
+
+<tr>
+<td>icon_link-rss.png</td>
+<td><a target="elsewhere" href="img/icon_link-rss.png"><img src="img/icon_link-rss.png"/></a></td>
+<td><a target="elsewhere" href="layout_link-fmt.htm">HERE</a></td>
+<td>...link to RSS feed</td>
+</tr>
+
+<tr>
+<th colspan="4">UNUSED</th>
+<tr>
+
+<tr>
+<td>icon_nav-top.png</td>
+<td><a target="elsewhere" href="img/icon_nav-top.png"><img src="img/icon_nav-top.png"/></a></td>
+<td></td>
+<td></td>
+</tr>
+
+<tr>
+<td>icon_nav-start.png</td>
+<td><a target="elsewhere" href="img/icon_nav-start.png"><img src="img/icon_nav-start.png"/></a></td>
+<td></td>
+<td></td>
+</tr>
+
+<tr>
+<td>icon_nav_end.png</td>
+<td><a target="elsewhere" href="img/icon_nav_end.png"><img src="img/icon_nav_end.png"/></a></td>
+<td></td>
+<td></td>
+</tr>
+
+<tr>
+<td>icon_question.png</td>
+<td><a target="elsewhere" href="img/icon_question.png"><img src="img/icon_question.png"/></a></td>
+<td></td>
+<td></td>
+</tr>
+
+<tr>
+<td>icon_trash.png</td>
+<td><a target="elsewhere" href="img/icon_trash.png"><img src="img/icon_trash.png"/></a></td>
+<td></td>
+<td></td>
+</tr>
+
+</table>
+
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/_index.html b/examples/webkit/webkit-guide/_index.html
new file mode 100644
index 0000000000..709f951c8f
--- /dev/null
+++ b/examples/webkit/webkit-guide/_index.html
@@ -0,0 +1,322 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<!-- examples.qdoc -->
+ <title>CSS: SAMPLE PAGES</title>
+ <link rel="stylesheet" type="text/css" href="style/style.css" />
+ <script src="scripts/jquery.js" type="text/javascript"></script>
+ <script src="scripts/functions.js" type="text/javascript"></script>
+ <script src="./scripts/superfish.js" type="text/javascript"></script>
+ <link rel="stylesheet" type="text/css" href="style/superfish.css" /> <script src="./scripts/narrow.js" type="text/javascript"></script>
+ <link rel="stylesheet" type="text/css" href="style/narrow.css" />
+</head>
+<body class="" onload="CheckEmptyAndLoadList();">
+
+ <style>
+div.header, div.toolbar, div.feedback, div#feedbackBox, div.footer, div.sidebar { display: none; background: pink }
+div.toc {
+ background: #dddddd;
+ border: thin solid #777777;
+ padding: 1em;
+ border-radius: 1em;
+ margin: 1em
+}
+div.toc li:before { color: lightcoral; text-transform: uppercase; }
+h3 { border-top: thick pink solid }
+h4 { border-top: medium gold solid }
+h5 { border-top: medium lightgreen solid }
+h3,h4,h5 { padding-top: 1em }
+li.level1 { margin-left: 0 }
+li.level2 { margin-left: 2em }
+li.level3 { margin-left: 4em }
+li.level4 { margin-left: 6em }
+li.level5 { margin-left: 8em }
+table { border: solid #777777 thin }
+tr:nth-of-type(even) { background: beige }
+tr:nth-of-type(odd) { background: lightblue }
+th {
+ background: #777777;
+ color: #ffffff;
+}
+
+img[src^='images/cnd_'] { float: right; margin: 1em ; padding: 1em; border-radius: 1em; border: thin #777777 solid; }
+tt, pre { background: #dddddd; border: thin #dddddd solid; }
+a[href^='http://waplabdc.nokia-boston.com'] { color: black; }
+a[href^='http://waplabdc.nokia-boston.com']:before { content: url(http://waplabdc.nokia-boston.com/browser/users/sierra/x/img/html.jpg); }
+ </style>
+ <div class="header" id="qtdocheader">
+ <div class="content">
+ <div id="nav-logo">
+ <a href="index.html">Home</a></div>
+ <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
+ <div id="narrowsearch"></div>
+ <div id="nav-topright">
+ <ul>
+ <li class="nav-topright-home"><a href="http://qt.nokia.com/">Qt HOME</a></li>
+ <li class="nav-topright-dev"><a href="http://developer.qt.nokia.com/">DEV</a></li>
+ <li class="nav-topright-labs"><a href="http://labs.qt.nokia.com/blogs/">LABS</a></li>
+ <li class="nav-topright-doc nav-topright-doc-active"><a href="http://doc.qt.nokia.com/">
+ DOC</a></li>
+ <li class="nav-topright-blog"><a href="http://blog.qt.nokia.com/">BLOG</a></li>
+ </ul>
+ </div>
+ <div id="shortCut">
+ <ul>
+ <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.7</a></span></li>
+ <li class="shortCut-topleft-active"><a href="http://doc.qt.nokia.com">ALL VERSIONS </a></li>
+ </ul>
+ </div>
+ <ul class="sf-menu" id="narrowmenu">
+ <li><a href="#">API Lookup</a>
+ <ul>
+ <li><a href="classes.html">Class index</a></li>
+ <li><a href="functions.html">Function index</a></li>
+ <li><a href="modules.html">Modules</a></li>
+ <li><a href="namespaces.html">Namespaces</a></li>
+ <li><a href="qtglobal.html">Global Declarations</a></li>
+ <li><a href="qdeclarativeelements.html">QML elements</a></li>
+ </ul>
+ </li>
+ <li><a href="#">Qt Topics</a>
+ <ul>
+ <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>
+ <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>
+ <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>
+ <li><a href="developing-with-qt.html">Cross-platform and Platform-specific</a></li>
+ <li><a href="platform-specific.html">Platform-specific info</a></li>
+ <li><a href="technology-apis.html">Qt and Key Technologies</a></li>
+ <li><a href="best-practices.html">How-To's and Best Practices</a></li>
+ </ul>
+ </li>
+ <li><a href="#">Examples</a>
+ <ul>
+ <li><a href="all-examples.html">Examples</a></li>
+ <li><a href="tutorials.html">Tutorials</a></li>
+ <li><a href="demos.html">Demos</a></li>
+ <li><a href="qdeclarativeexamples.html">QML Examples</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </div>
+ <div class="wrapper">
+ <div class="hd">
+ <span></span>
+ </div>
+ <div class="bd group">
+ <div class="sidebar">
+ <div class="searchlabel">
+ Search index:</div>
+ <div class="search" id="sidebarsearch">
+ <form id="qtdocsearch" action="" onsubmit="return false;">
+ <fieldset>
+ <input type="text" name="searchstring" id="pageType" value="" />
+ <div id="resultdialog">
+ <a href="#" id="resultclose">Close</a>
+ <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p>
+ <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p>
+ <ul id="resultlist" class="all">
+ </ul>
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ <div class="box first bottombar" id="lookup">
+ <h2 title="API Lookup"><span></span>
+ API Lookup</h2>
+ <div id="list001" class="list">
+ <ul id="ul001" >
+ <li class="defaultLink"><a href="classes.html">Class index</a></li>
+ <li class="defaultLink"><a href="functions.html">Function index</a></li>
+ <li class="defaultLink"><a href="modules.html">Modules</a></li>
+ <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
+ <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
+ <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="box bottombar" id="topics">
+ <h2 title="Qt Topics"><span></span>
+ Qt Topics</h2>
+ <div id="list002" class="list">
+ <ul id="ul002" >
+ <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li>
+ <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>
+ <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li>
+ <li class="defaultLink"><a href="developing-with-qt.html">Cross-platform and Platform-specific</a></li>
+ <li class="defaultLink"><a href="platform-specific.html">Platform-specific info</a></li>
+ <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li>
+ <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="box" id="examples">
+ <h2 title="Examples"><span></span>
+ Examples</h2>
+ <div id="list003" class="list">
+ <ul id="ul003">
+ <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
+ <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
+ <li class="defaultLink"><a href="demos.html">Demos</a></li>
+ <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="wrap">
+ <div class="toolbar">
+ <div class="breadcrumb toolblock">
+ <ul>
+ <li class="first"><a href="index.html">Home</a></li>
+ <!-- Bread crumbs goes here -->
+ <li>CSS: SAMPLE PAGES</li> </ul>
+ </div>
+ <div class="toolbuttons toolblock">
+ <ul>
+ <li id="smallA" class="t_button">A</li>
+ <li id="medA" class="t_button active">A</li>
+ <li id="bigA" class="t_button">A</li>
+ <li id="print" class="t_button"><a href="javascript:this.print();">
+ <span>Print</span></a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="content mainContent">
+<div class="toc">
+<h3><a name="toc">Contents</a></h3>
+<ul>
+<li class="level1"><a href="#css-sample-pages">CSS: SAMPLE PAGES</a></li>
+<li class="level2"><a href="#media-queries">Media Queries</a></li>
+<li class="level2"><a href="#selectors">Selectors</a></li>
+<li class="level2"><a href="#visual-effects">Visual Effects</a></li>
+<li class="level2"><a href="#dynamic-css">Dynamic CSS</a></li>
+<li class="level1"><a href="#storage">Storage</a></li>
+</ul>
+</div>
+<h1 class="title">CSS: SAMPLE PAGES</h1>
+<span class="subtitle"></span>
+<!-- $$$examples-description -->
+<div class="descr"> <a name="details"></a>
+<a name="css-sample-pages"></a>
+<h2>CSS: SAMPLE PAGES</h2>
+<a name="media-queries"></a>
+<h3>1. Media Queries</h3>
+<ol type="1">
+<li><a target="test" href="mob_mediaquery.htm">MEDIA-QUERY, BASIC</a>: produces message indicating browser class (desktop/touch/low-end mobile)</li>
+<li><a target="test" href="mob_layout.htm">MEDIA-QUERY, LAYOUT</a>: same, but produces various skeletal layouts using media query criteria; large 3-column layout must appear only on desktop browser</li>
+<li><a target="test" href="mob_condjs.htm">MEDIA-QUERY, STYLEMEDIA</a>: Same as #1, but JS produces corresponding message via StyleMedia API</li>
+</ol>
+<a name="selectors"></a>
+<h3>2. Selectors</h3>
+<ol type="1">
+<li><a target="test" href="layout_link-fmt.htm">SELECTOR, ATTRIBUTE PREFIX/SUFFIX</a>: links appear w/different icons based on URL prefix/suffix; linebreaks should not appear within inline links</li>
+<li><a target="test" href="form_tapper.htm">SELECTOR, FORMS, TAP</a>: radio/checkbox inputs can be tapped (only 1 at a time within 'radio' set; any number within 'checkbox' set)</li>
+<li><a target="test" href="form_toggler.htm">SELECTOR, FORMS, TOGGLE</a>: radio/checkbox inputs can be toggled (only 1 at a time within 'radio' inputs; any number within 'checkbox' inputs); 2 "binary" examples at bottom use custom text</li>
+<li><a target="test" href="layout_tbl-keyhole.htm">SELECTOR, NAVIGATIONAL, TABLE</a>: pressing &quot;view listings&quot; displays stacked table rows, one at a time</li>
+<li><a target="test" href="css3_sel-nth.htm">SELECTOR, POSITIONAL</a>: displays 4x6 icon grid, implemted via nth-of-type()</li>
+</ol>
+<a name="visual-effects"></a>
+<h3>3. Visual Effects</h3>
+<ol type="1">
+<li><a target="test" href="css3_backgrounds.htm">CSS, BACKGROUNDS</a>: selected accordion tabs display both gradient background and icon; unselected only displays icon; uses scaleY transition</li>
+<li><a target="test" href="css3_border-img.htm">CSS, BORDER IMAGE</a>: border image surrounds box</li>
+<li><a target="test" href="css3_shadow.htm">CSS, BOX-SHADOW, PLAIN</a>: nav element has shadow; icons appear smaller while pressed</li>
+<li><a target="test" href="css3_gradientBack.htm">CSS, GRADIENT, BACKGROUND</a>: background fades vertically from light to dark</li>
+<li><a target="test" href="css3_gradientBackStop.htm">CSS, GRADIENT, BACKGROUND, COLOR-STOP</a>: as you scroll down page, background fades vertically from dark to light and back to dark again</li>
+<li><a target="test" href="css3_gradientButton.htm">CSS, GRADIENT, BUTTON</a>: buttons appear with vertical shading, appearing w/inverted gradient when pressed</li>
+<li><a target="test" href="css3_grad-radial.htm">CSS, GRADIENT, RADIAL</a>: touching within box produces colorful *splat* effect for duration of touch</li>
+<li><a target="test" href="css3_mask-grad.htm">CSS, MASK, GRADIENT</a>: images appear w/gradient; touching them removes gradient</li>
+<li><a target="test" href="css3_mask-img.htm">CSS, MASK, IMAGE</a>: image fills screen but fades to black around the edges</li>
+<li><a target="test" href="css3_reflect.htm">CSS, REFLECTION</a>: heading and image both appear w/mirror reflections along bottom</li>
+<li><a target="test" href="css3_scroll.htm">CSS, SCROLLBARS</a>: code block scrollable via big buttons</li>
+<li><a target="test" href="css3_text-overflow.htm">CSS, TEXT-OVERFLOW</a>: items appear w/ellipses; touching them expands them; pressing (X) collapses them</li>
+<li><a target="test" href="css3_text-shadow.htm">CSS, TEXT-SHADOW</a>: heading text appears with shadow</li>
+<li><a target="test" href="css3_text-stroke.htm">CSS, TEXT-STROKE</a>: first heading appears w/black outline</li>
+</ol>
+<a name="dynamic-css"></a>
+<h3>4. Dynamic CSS</h3>
+<ol type="1">
+<li><a target="test" href="anim_demo-rotate.htm">ANIMATION, DEMO, ROTATE</a>: animated demo of rotating boxes</li>
+<li><a target="test" href="anim_demo-scale.htm">ANIMATION, DEMO, SCALE</a>: animated demo of shrinking/expanding box</li>
+<li><a target="test" href="anim_demo-skew.htm">ANIMATION, DEMO, SKEW</a>: animated demo of box being pushed and piulled around</li>
+<li><a target="test" href="anim_pulse.htm">ANIMATION, KEYFRAME, PULSE</a>: pressing icons causes them to pulse indefinitely</li>
+<li><a target="test" href="anim_slide1.htm">ANIMATION, KEYFRAME, SLIDING</a>: drill-down menus</li>
+<li><a target="test" href="css3_multicol.htm">ANIMATION, KEYFRAME, BANNER</a>: banner scrolls through 5 colorful items</li>
+<li><a target="test" href="anim_tabbedSkew.htm">ANIMATION, TRANSFORM, SKEWED TABS</a>: touching parts of cube displays different tabbed text</li>
+<li><a target="test" href="anim_accord.htm">ANIMATION, TRANSITION, CHAINED, ACCORDION</a>: tapping icon animates in collapsed accordions; tapping them animates in display of subheads; tapping anywhere else reverses animation sequence, collapsing back to initial icon</li>
+<li><a target="test" href="anim_panel.htm">ANIMATION, TRANSITION, MAX-WIDTH, PANEL</a>: pressing icon animates to expand panel of choices; pressing anywhere collapses panel back down to initial icon</li>
+<li><a target="test" href="anim_skew.htm">ANIMATION, TRANSITION, SKEW</a>: tapping items causes them to wipe off right edge w/skew effect; remainder re-pack vertically; touching each category icon removes non-matching items and drops down matching ones</li>
+<li><a target="test" href="anim_gallery.htm">ANIMATION, TRANSITION, TRANSLATE, GALLERY</a>: tapping images adjacent to main image animates them in; tapping current image flips to display text; w/text displaying, tapping adjacent image animates both effects @ same time</li>
+</ol>
+
+<a name="storage"></a>
+<h2>5. Storage</h2>
+
+<ol type="1">
+<li><a target="test" href="storage.htm">LOCAL/SESSION STORAGE</a>:
+When opened for first time, form opens featuring
+login/password/credit-card fields. Fill them out. Each input's
+background will go pink if input is invalid. Login & password
+validate simply as "required" so any string will do. Credit card
+validates as 16-digit numeral. After filling out, press dismiss box.
+Then quit & reopen browser, go back to page, and press (i) info icon
+to get back into form. login/password should be same as initially
+entered (localStorage), but credit-card data s/b absent
+(sessionStorage).
+
+</li>
+</ol>
+
+</div>
+<!-- @@@examples -->
+ <div class="feedback t_button">
+ [+] Documentation Feedback</div>
+ </div>
+ </div>
+ </div>
+ <div class="ft">
+ <span></span>
+ </div>
+ </div>
+ <div class="footer">
+ <p>
+ <acronym title="Copyright">&copy;</acronym> 2008-2010 Nokia Corporation and/or its
+ subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation
+ in Finland and/or other countries worldwide.</p>
+ <p>
+ All other trademarks are property of their respective owners. <a title="Privacy Policy"
+ href="http://qt.nokia.com/about/privacy-policy">Privacy Policy</a></p>
+ <br />
+ <p>
+ Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.</p>
+ <p>
+ Alternatively, this document may be used under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU
+ Free Documentation License version 1.3</a>
+ as published by the Free Software Foundation.</p>
+ </div>
+ <div id="feedbackBox">
+ <div id="feedcloseX" class="feedclose t_button">X</div>
+ <form id="feedform" action="http://doc.qt.nokia.com/docFeedbck/feedback.php" method="get">
+ <p id="noteHead">Thank you for giving your feedback.</p> <p class="note">Make sure it is related to this specific page. For more general bugs and
+ requests, please use the <a href="http://bugreports.qt.nokia.com/secure/Dashboard.jspa">Qt Bug Tracker</a>.</p>
+ <p><textarea id="feedbox" name="feedText" rows="5" cols="40"></textarea></p>
+ <p><input id="feedsubmit" class="feedclose" type="submit" name="feedback" /></p>
+ </form>
+ </div>
+ <div id="blurpage">
+ </div>
+ <script src="scripts/functions.js" type="text/javascript"></script>
+ <!-- <script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-4457116-5']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ </script> -->
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_accord.htm b/examples/webkit/webkit-guide/anim_accord.htm
new file mode 100644
index 0000000000..9efd3b1a0e
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_accord.htm
@@ -0,0 +1,122 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Nested Accordion</title>
+<link href='css/anim_accord.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="main">
+<article>
+
+<dl id="accordion" class="collapsed">
+
+<dt><a href="#">Event Info</a></dt>
+<dd>
+<ul>
+<li><a href="#">Travel</a></li>
+<li><a href="#">Area Info</a></li>
+<li><a href="#">Hospitality</a></li>
+<li><a href="#">Schedule of Events</a></li>
+<li><a href="#">Spectator Guide</a></li>
+<li><a href="#">Contact Us</a></li>
+</ul>
+</dd>
+<dt><a href="#">Team Info</a></dt>
+<dd>
+<ul>
+<li><a href="#">Team Captain</a></li>
+<li><a href="#">Team Members</a></li>
+<li><a href="#">Team Standings</a></li>
+</ul>
+</dd>
+<dt><a href="#">Course</a></dt>
+<dd>
+<ul>
+<li><a href="#">Overview</a></li>
+<li><a href="#">Tour</a></li>
+<li><a href="#">History</a></li>
+</ul>
+</dd>
+<dt><a href="#">History</a></dt>
+<dd>
+<ul>
+<li><a href="#">Past Results</a></li>
+<li><a href="#">U.S. Player Records</a></li>
+<li><a href="#">European Player Records</a></li>
+<li><a href="#">All-Time Records</a></li>
+<li><a href="#">The Trophy</a></li>
+</ul>
+</dd>
+<dt><a href="#">News</a></dt>
+<dd>
+<ul>
+<li><a href="#">News Stotries</a></li>
+<li><a href="#">Interviews</a></li>
+<li><a href="#">Photo Gallery</a></li>
+<li><a href="#">Videos</a></li>
+</ul>
+</dd>
+</dl>
+
+<h4>Nested Accordion</h4>
+
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+
+</article>
+</section>
+<script src="js/anim_accord.js"></script>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_demo-rotate.htm b/examples/webkit/webkit-guide/anim_demo-rotate.htm
new file mode 100644
index 0000000000..299fd98327
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_demo-rotate.htm
@@ -0,0 +1,63 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>transforms: rotate</title>
+
+<link href='css/anim_demo-rotate.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="rotate">
+Rotate: from 0 to 180&deg;, then to 360&deg;<br/>(Origin: center)
+</section>
+
+<section class="rotateOrigin">
+Rotate: from 0 to -180&deg;, then to -360&deg;<br/>(Origin: top left)
+</section>
+
+<section class="end">
+(The End)
+</section>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_demo-scale.htm b/examples/webkit/webkit-guide/anim_demo-scale.htm
new file mode 100644
index 0000000000..e6f0f79c26
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_demo-scale.htm
@@ -0,0 +1,67 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>transforms: scale</title>
+
+<link href='css/anim_demo-scale.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="scale">
+Scale: from 0 to 0.5, to 1.5 and back.<br/>(Origin: bottom)
+</section>
+
+<section class="scaleX">
+ScaleX: from 0 to 0.5, to 1.5 and back.<br/>(Origin: left)
+</section>
+
+<section class="scaleY">
+ScaleY: from 0 to 0.5, to 1.5 and back.<br/>(Origin: center)
+</section>
+
+<section class="end">
+(The End)
+</section>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_demo-skew.htm b/examples/webkit/webkit-guide/anim_demo-skew.htm
new file mode 100644
index 0000000000..c183f646d2
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_demo-skew.htm
@@ -0,0 +1,62 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>transforms: skew</title>
+<link href='css/anim_demo-skew.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="skew">
+Skew: from 30&deg; to -30&deg; and back.<br/>(Origin: bottom)
+</section>
+
+<section class="skewY">
+SkewY: from 30&deg; to -30&deg; and back.<br/>(Origin: left)
+</section>
+
+<section class="end">
+(The End)
+</section>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_gallery.htm b/examples/webkit/webkit-guide/anim_gallery.htm
new file mode 100644
index 0000000000..3bb7e07f2c
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_gallery.htm
@@ -0,0 +1,114 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Image Gallery</title>
+<link href='css/anim_gallery.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="gallery"><div>
+<img src="img/gal1.jpg"/>
+<div>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</div>
+</div><div>
+<img src="img/gal2.jpg"/>
+<div>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+Aenean elementum arcu sed nibh faucibus pellentesque.
+Aenean vestibulum egestas metus, eu sodales dolor venenatis quis.
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.
+Donec a massa felis, a congue purus. Nullam et turpis diam.
+Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</div>
+</div><div>
+<img src="img/gal3.jpg"/>
+<div>
+Aliquam erat volutpat. Mauris tempor, urna at dignissim pellentesque, velit lacus dictum sem, non porttitor felis nulla nec risus.
+Donec a massa felis, a congue purus. Nullam et turpis diam.
+Donec feugiat gravida viverra.
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.
+Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</div>
+</div><div>
+<img src="img/gal4.jpg"/>
+<div>
+Donec feugiat gravida viverra.
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+Aliquam erat volutpat. Mauris tempor, urna at dignissim pellentesque, velit lacus dictum sem, non porttitor felis nulla nec risus.
+</div>
+</div><div>
+<img src="img/gal5.jpg"/>
+<div>
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.
+Aliquam erat volutpat. Mauris tempor, urna at dignissim pellentesque, velit lacus dictum sem, non porttitor felis nulla nec risus.
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+</div>
+</div><div>
+<img src="img/gal6.jpg"/>
+<div>
+Donec feugiat gravida viverra.
+Aenean elementum arcu sed nibh faucibus pellentesque.
+Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</div>
+</div><div>
+<img src="img/gal7.jpg"/>
+<div>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+Aliquam erat volutpat. Mauris tempor, urna at dignissim pellentesque, velit lacus dictum sem, non porttitor felis nulla nec risus.
+</div>
+</div><div>
+<img src="img/gal8.jpg"/>
+<div>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+Aliquam erat volutpat. Mauris tempor, urna at dignissim pellentesque, velit lacus dictum sem, non porttitor felis nulla nec risus.
+Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</div>
+</div></section>
+<script src="js/anim_gallery.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_panel.htm b/examples/webkit/webkit-guide/anim_panel.htm
new file mode 100644
index 0000000000..07ecd62177
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_panel.htm
@@ -0,0 +1,63 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Slide-out Panel</title>
+<link href='css/anim_panel.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section onclick="javascript:void(0)">
+<nav id="panel" class="collapsed">
+<img class="button" src="img/ic_c_032.png" onclick="share()"/>
+<img class="option" src="img/ic_ni_032.png" onclick="debug('Ni')"/>
+<img class="option" src="img/ic_fe_032.png" onclick="debug('Fe')"/>
+<img class="option" src="img/ic_he_032.png" onclick="debug('He')"/>
+<img class="option" src="img/ic_o_032.png" onclick="debug('O')"/>
+<img class="option" src="img/ic_na_032.png" onclick="debug('Na')"/>
+<img class="option" src="img/ic_zn_032.png" onclick="debug('Zn')"/>
+<span class="force">&nbsp;</span>
+</nav>
+<div id="dbg">Press the icon, then choose an option if you wish.</div>
+</section>
+<script src="js/anim_panel.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_pulse.htm b/examples/webkit/webkit-guide/anim_pulse.htm
new file mode 100644
index 0000000000..97666c997f
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_pulse.htm
@@ -0,0 +1,71 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Pulse</title>
+<link href='css/anim_pulse.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<nav>
+<a href="#a" id="a"></a>
+<a href="#b" id="b"></a>
+<a href="#c" id="c"></a>
+<a href="#d" id="d"></a>
+<a href="#e" id="e"></a>
+<a href="#f" id="f"></a>
+<span class="force">&nbsp;</span>
+</nav>
+<h3>Animated Pulse</h3>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_skew.htm b/examples/webkit/webkit-guide/anim_skew.htm
new file mode 100644
index 0000000000..077fe17a5e
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_skew.htm
@@ -0,0 +1,80 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Transitions with Skew Transforms</title>
+<link href="css/anim_skew.css" rel="stylesheet" type="text/css" />
+<style id="custom"></style>
+</head>
+<body>
+<section class="items">
+<div title="cat1">Item #1</div>
+<div title="cat2">Item #2</div>
+<div title="cat1">Item #3</div>
+<div title="cat3">Item #4</div>
+<div title="cat4">Item #5</div>
+<div title="cat1">Item #6</div>
+<div title="cat3">Item #7</div>
+<div title="cat2">Item #8</div>
+<div title="cat4">Item #9</div>
+<div title="cat1">Item #10</div>
+<div title="cat2">Item #11</div>
+<div title="cat3">Item #12</div>
+<div title="cat4">Item #13</div>
+<div title="cat1">Item #14</div>
+<div title="cat2">Item #15</div>
+</section>
+
+<nav>
+<div>&nbsp;</div>
+<div class="cat1">&nbsp;</div>
+<div class="cat2">&nbsp;</div>
+<div class="cat4">&nbsp;</div>
+<div class="cat3">&nbsp;</div>
+</nav>
+
+<script src="js/anim_skew.js"></script>
+<!--
+<script src="js/mobile.js"></script>
+-->
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_slide1.htm b/examples/webkit/webkit-guide/anim_slide1.htm
new file mode 100644
index 0000000000..866cecc44b
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_slide1.htm
@@ -0,0 +1,61 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Drilldown Sliders</title>
+<link href="css/anim_slide.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<a id='out'></a>
+<div id='in' class='panel'>
+<h1>Level 1</h1>
+<ul>
+<li><a href='anim_slide2.htm#in'>Level 2, Option A</a></li>
+<li><a href='anim_slide2.htm#in'>Level 2, Option B</a></li>
+<li><a href='anim_slide2.htm#in'>Level 2, Option C</a></li>
+<li><a href='anim_slide2.htm#in'>Level 2, Option D</a></li>
+<li><a href='anim_slide2.htm#in'>Level 2, Option E</a></li>
+</ul>
+</div>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_slide2.htm b/examples/webkit/webkit-guide/anim_slide2.htm
new file mode 100644
index 0000000000..474de36d6f
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_slide2.htm
@@ -0,0 +1,62 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Drilldown Sliders</title>
+<link href="css/anim_slide.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<a id='out'></a>
+<div id='in' class='panel'>
+<h1>Level 2</h1>
+<a class='go_out' href='anim_slide1.htm#out'></a>
+<ul>
+<li><a href='anim_slide3.htm#in'>Level 3, Option A</a></li>
+<li><a href='anim_slide3.htm#in'>Level 3, Option B</a></li>
+<li><a href='anim_slide3.htm#in'>Level 3, Option C</a></li>
+<li><a href='anim_slide3.htm#in'>Level 3, Option D</a></li>
+<li><a href='anim_slide3.htm#in'>Level 3, Option E</a></li>
+</ul>
+</div>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_slide3.htm b/examples/webkit/webkit-guide/anim_slide3.htm
new file mode 100644
index 0000000000..0da926ea63
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_slide3.htm
@@ -0,0 +1,65 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Drilldown Sliders</title>
+<link href="css/anim_slide.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<a id='out'></a>
+<div id='in' class='panel'>
+<h1>Level 3</h1>
+
+<a class='go_out' href='anim_slide2.htm#out'></a>
+
+<article>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque.
+</article>
+
+</div>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/anim_tabbedSkew.htm b/examples/webkit/webkit-guide/anim_tabbedSkew.htm
new file mode 100644
index 0000000000..387e0a7bb1
--- /dev/null
+++ b/examples/webkit/webkit-guide/anim_tabbedSkew.htm
@@ -0,0 +1,88 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Transformed Tabs</title>
+<link href='css/anim_tabbedSkew.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<nav>
+<a id="l1" href="#a1">&nbsp;</a>
+<a id="l2" href="#a2">&nbsp;</a>
+<a id="l3" href="#a3">&nbsp;</a>
+</nav>
+<article id="a1">
+<h3>Tab #1</h3>
+<div>&nbsp;</div>
+<p>Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis
+ante, id mollis risus lectus ornare nisl. Lorem ipsum dolor sit amet,
+consectetur adipiscing elit. Donec feugiat gravida viverra. Vivamus
+ipsum felis, cursus sed venenatis nec, tempus ac tellus. Aenean
+elementum arcu sed nibh faucibus pellentesque. </p>
+</article>
+<article id="a2">
+<h3>Tab #2</h3>
+<div>&nbsp;</div>
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl.
+
+</article>
+<article id="a3">
+<h3>Tab #3</h3>
+<div>&nbsp;</div>
+
+Donec feugiat gravida viverra. Vivamus ipsum felis, cursus sed
+venenatis nec, tempus ac tellus. Praesent luctus, risus eu vestibulum
+mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+Nullam et turpis diam. Aenean vestibulum egestas metus, eu sodales
+dolor venenatis quis. Aenean augue orci, facilisis et convallis ut,
+egestas at neque.
+
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css/anim_accord.css b/examples/webkit/webkit-guide/css/anim_accord.css
new file mode 100755
index 0000000000..c9c013affa
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_accord.css
@@ -0,0 +1,246 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ width : 100;
+}
+
+body > section {
+ border-radius : 1em;
+ background : #ffffff;
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ min-height : 70%;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
+.nav > a {
+ display : inline-block;
+ width : 48px;
+ height : 48px;
+}
+
+h1, h2, h3, h4 {
+ margin-top : 0.0em;
+ font-size : smaller;
+ padding-top : 1em;
+}
+
+body > section.main {
+ position : absolute;
+ left : 1em;
+ right : 1em;
+ top : 1em;
+ min-height : 50%;
+ border-radius : 0.5em;
+ background : #aaaaaa;
+ padding : 0;
+}
+
+section.main > article {
+ background : #ffffff;
+ padding : 1em;
+ margin-bottom : 10em;
+ border-radius : 0.5em;
+}
+
+#accordion,
+#accordion > dt,
+#accordion > dd,
+{
+ display : block;
+}
+
+#accordion > dt {
+ border-top : thin solid #777777;
+}
+
+#accordion > dd {
+ border-bottom : thin solid #777777;
+}
+
+#accordion > dd {
+ background-image : -webkit-gradient(linear,center top,center bottom,from(#aaaaaa),to(#ffffff));
+}
+
+#accordion.collapsed {
+ background-size : auto;
+ background-image : url(../img/icon_expand-nav.png);
+ background-repeat : no-repeat;
+ background-position : 0.25em 0.25em;
+}
+
+#accordion {
+ position : absolute;;
+ right : 2em;
+ top : 0em;
+ overflow : hidden;
+ background : #ffffff;
+ cursor : pointer;
+ z-index : 100;
+ font-weight : bold;
+}
+
+#accordion.expanded {
+ border : thin solid #206ead;
+ width : 80%;
+ height : 90%;
+ -webkit-transition:
+ width 0.5s ease-in-out 0.0s,
+ height 0.5s ease-in-out 0.5s
+ ;
+}
+
+#accordion.collapsed {
+ width : 15%;
+ height : 9%;
+ -webkit-transition:
+ height 0.5s ease-in-out 0.0s,
+ width 0.5s ease-in-out 0.5s
+ ;
+}
+
+#accordion.collapsed > dt,
+#accordion.collapsed > dd {
+ -webkit-transform : translate(100%);
+ -webkit-transition : -webkit-transform 0.5s ease-in-out 0.5s;
+}
+
+#accordion.expanded > dt,
+#accordion.expanded > dd {
+ -webkit-transform : translate(0%);
+ -webkit-transition : -webkit-transform 0.5s ease-in-out 0.0s;
+}
+
+#accordion > dt > a {
+ margin-left : 0.5em;
+}
+
+#accordion > dt ,
+#accordion > dd {
+ padding : 0.5em;
+}
+
+#accordion > dt ~ dd {
+ margin : 0;
+}
+
+#accordion > dd > ul,
+#accordion > dd > ul > li
+{
+ padding : 0;
+ margin : 0;
+}
+
+#accordion a,
+#accordion a:active,
+#accordion a:hover,
+#accordion a:visited
+{
+ text-decoration : none;
+ color : #000000;
+}
+
+#accordion > dt.expanded:before {
+ content : url(../img/icon_head-expanded_x13.png);
+}
+
+#accordion > dt.collapsed:before {
+ content : url(../img/icon_head-collapsed_x13.png);
+}
+
+#accordion > dt.expanded {
+ background-image : -webkit-gradient(linear, center top, center bottom, from(#aaaaaa), to(#ffffff));
+}
+
+#accordion > dt.collapsed {
+ background-image : -webkit-gradient(linear, center top, center bottom, from(#aaaaaa), to(#ffffff));
+}
+
+#accordion > dt + dd {
+ background : #ffffff;
+ display : block;
+}
+
+#accordion dd {
+ overflow : none;
+}
+
+#accordion > dt.collapsed + dd {
+ max-height : 0%;
+ opacity : 0;
+ -webkit-transform : scaleY(0);
+ -webkit-transition : all 0.5s ease-in-out;
+}
+
+#accordion > dt.expanded + dd {
+ max-height : 50%;
+ opacity : 1;
+ -webkit-transform : scaleY(1);
+ -webkit-transition : all 0.5s ease-in-out;
+}
+
+#accordion > dd {
+ margin : 0;
+ padding : 0;
+}
+
+#accordion > dd > ul > li {
+ padding-top : 0.25em;
+ padding-bottom : 0.5em;
+ padding-left : 1.0em;
+ padding-right : 1.0em;
+}
+
+#accordion> dt.collapsed:last-of-type {
+ border-bottom : thin solid #aaaaaa;
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_demo-rotate.css b/examples/webkit/webkit-guide/css/anim_demo-rotate.css
new file mode 100755
index 0000000000..fa3bd0dee8
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_demo-rotate.css
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+body {
+ background : #aaaaaa;
+ font-weight : bold;
+}
+
+section {
+ color : #ffffff;
+ background : #777777;
+ font-size : x-large;
+ -webkit-transform : translate(-150%) scale(1);
+ position : absolute;
+ text-align : center;
+ padding : 1em;
+ top : 3em;
+ left : 3em;
+ bottom : 3em;
+ right : 3em;
+}
+
+@-webkit-keyframes demoRotate {
+ 0% { -webkit-transform : translate(-150%); }
+ 10% { -webkit-transform : rotate(0deg) translate(0); }
+ 50% { -webkit-transform : rotate(180deg) translate(0); }
+ 90% { -webkit-transform : rotate(360deg) translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+@-webkit-keyframes demoRotateOrigin {
+ 0% { -webkit-transform : rotate(0deg) translate(-150%); }
+ 10% { -webkit-transform : rotate(0deg) translate(0); }
+ 50% { -webkit-transform : rotate(-180deg) translate(0); }
+ 90% { -webkit-transform : rotate(-360deg) translate(0); }
+ 100% { -webkit-transform : rotate(-360deg) translate(150%) }
+}
+
+@-webkit-keyframes end {
+ 0% { -webkit-transform : translate(150%); }
+ 30% { -webkit-transform : translate(0); }
+ 70% { -webkit-transform : translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+.rotate {
+ -webkit-animation : demoRotate 9s 2s;
+ -webkit-transform-origin : center;
+ -webkit-animation-timing-function : linear;
+}
+.rotateOrigin {
+ -webkit-animation : demoRotateOrigin 9s 12s;
+ -webkit-transform-origin : top left;
+ -webkit-animation-timing-function : linear;
+}
+.end {
+ -webkit-animation : end 3s 22s;
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_demo-scale.css b/examples/webkit/webkit-guide/css/anim_demo-scale.css
new file mode 100755
index 0000000000..4af469a61e
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_demo-scale.css
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-weight : bold;
+}
+
+section {
+ color : #ffffff;
+ background : #777777;
+ font-size : x-large;
+ -webkit-transform : translate(-150%) scale(1);
+ position : absolute;
+ text-align : center;
+ padding : 1em;
+ top : 3em;
+ left : 3em;
+ bottom : 3em;
+ right : 3em;
+}
+
+@-webkit-keyframes demoScale {
+ 0% { -webkit-transform : translate(-150%) scale(1); }
+ 10% { -webkit-transform : scale(1.0) translate(0); }
+ 30% { -webkit-transform : scale(0.5) translate(0); }
+ 50% { -webkit-transform : scale(1.0) translate(0); }
+ 70% { -webkit-transform : scale(1.5) translate(0); }
+ 90% { -webkit-transform : scale(1.0) translate(0); }
+ 100% { -webkit-transform : translate(150%) scale(1); }
+}
+
+@-webkit-keyframes demoScaleX {
+ 0% { -webkit-transform : translate(-150%) scale(1); }
+ 10% { -webkit-transform : scaleX(1.0) translate(0); }
+ 30% { -webkit-transform : scaleX(0.5) translate(0); }
+ 50% { -webkit-transform : scaleX(1.0) translate(0); }
+ 70% { -webkit-transform : scaleX(1.5) translate(0); }
+ 90% { -webkit-transform : scaleX(1.0) translate(0); }
+ 100% { -webkit-transform : translate(150%) scale(1); }
+}
+
+@-webkit-keyframes demoScaleY {
+ 0% { -webkit-transform : translate(-150%) scale(1); }
+ 10% { -webkit-transform : scaleY(1.0) translate(0); }
+ 30% { -webkit-transform : scaleY(0.5) translate(0); }
+ 50% { -webkit-transform : scaleY(1.0) translate(0); }
+ 70% { -webkit-transform : scaleY(1.5) translate(0); }
+ 90% { -webkit-transform : scaleY(1.0) translate(0); }
+ 100% { -webkit-transform : translate(150%) scale(1); }
+}
+
+@-webkit-keyframes end {
+ 0% { -webkit-transform : translate(150%); }
+ 30% { -webkit-transform : translate(0); }
+ 70% { -webkit-transform : translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+.scale {
+ -webkit-animation : demoScale 9s 2s;
+ -webkit-transform-origin : bottom;
+}
+.scaleX {
+ -webkit-animation : demoScaleX 9s 12s;
+ -webkit-transform-origin : left;
+}
+.scaleY {
+ -webkit-animation : demoScaleY 9s 22s;
+ -webkit-transform-origin : center;
+}
+.end {
+ -webkit-animation : end 3s 32s;
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_demo-skew.css b/examples/webkit/webkit-guide/css/anim_demo-skew.css
new file mode 100755
index 0000000000..2d90bf9574
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_demo-skew.css
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-weight : bold;
+}
+
+section {
+ color : #ffffff;
+ background : #777777;
+ font-size : x-large;
+ -webkit-transform : translate(-150%) scale(1);
+ position : absolute;
+ text-align : center;
+ padding : 1em;
+ top : 3em;
+ left : 3em;
+ bottom : 3em;
+ right : 3em;
+}
+
+@-webkit-keyframes demoSkew {
+ 0% { -webkit-transform : translate(-150%); }
+ 10% { -webkit-transform : skew(0deg) translate(0); }
+ 30% { -webkit-transform : skew(30deg) translate(0); }
+ 50% { -webkit-transform : skew(0deg) translate(0); }
+ 70% { -webkit-transform : skew(-30deg) translate(0); }
+ 90% { -webkit-transform : skew(0deg) translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+@-webkit-keyframes demoSkewY {
+ 0% { -webkit-transform : translate(-150%); }
+ 10% { -webkit-transform : skewY(0deg) translate(0); }
+ 30% { -webkit-transform : skewY(30deg) translate(0); }
+ 50% { -webkit-transform : skewY(0deg) translate(0); }
+ 70% { -webkit-transform : skewY(-30deg) translate(0); }
+ 90% { -webkit-transform : skewY(0deg) translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+@-webkit-keyframes end {
+ 0% { -webkit-transform : translate(150%); }
+ 30% { -webkit-transform : translate(0); }
+ 70% { -webkit-transform : translate(0); }
+ 100% { -webkit-transform : translate(150%); }
+}
+
+.skew {
+ -webkit-animation : demoSkew 9s 2s;
+ -webkit-transform-origin : bottom;
+}
+.skewY {
+ -webkit-animation : demoSkewY 9s 12s;
+ -webkit-transform-origin : left;
+}
+.end {
+ -webkit-animation : end 3s 22s;
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_gallery.css b/examples/webkit/webkit-guide/css/anim_gallery.css
new file mode 100755
index 0000000000..fe14aa263c
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_gallery.css
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+ background : #444444;
+}
+.gallery > div > div {
+ border-radius : 1.0em;
+ padding : 1em;
+ background : #dddddd;
+ min-height : 75%;
+}
+.gallery > div {
+ -webkit-transition : all 0.5s ease-in-out;
+ z-index : 0;
+ position : absolute;
+ top : 2.0em;
+ bottom : 2.0em;
+ left : 2.0em;
+ right : 2.0em;
+}
+.gallery > div.selected {
+ -webkit-transform : translate(0) scale(1);
+ opacity : 1.0;
+ z-index : 1;
+}
+.gallery > div.queueR {
+ -webkit-transform : translate(70%) scale(0.5);
+ opacity : 0.75;
+}
+.gallery > div.queueL {
+ -webkit-transform : translate(-70%) scale(0.5);
+ opacity : 0.75;
+}
+.gallery > div.hideR {
+ -webkit-transform : translate(200%) scale(0.5);
+ opacity : 0.0;
+}
+.gallery > div.hideL {
+ -webkit-transform : translate(-200%) scale(0.5);
+ opacity : 0.0;
+}
+.gallery img {
+ max-width : 100%;
+ max-height : 100%;
+ border-radius : 1.0em;
+}
+
+.gallery > #reveal > div, .gallery > div > img {
+ -webkit-transform : scaleX(1) scaleY(1);
+ -webkit-transition : -webkit-transform 0.25s ease-out 0.25s;
+}
+.gallery > div > div, .gallery > #reveal > img {
+ -webkit-transform : scaleX(0) scaleY(1);
+ -webkit-transition : -webkit-transform 0.25s ease-out;
+}
+
+section > div {
+ text-align : center;
+}
+
+section > div > img {
+ display : inline-block;
+}
+
+section > div > div {
+ position : absolute;
+ top : 0;
+ left : 1.5em;
+ right : 1.5em;
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_panel.css b/examples/webkit/webkit-guide/css/anim_panel.css
new file mode 100755
index 0000000000..87037c9a9e
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_panel.css
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+section {
+ background : #aaaaaa;
+ position : absolute;
+ left : 1em;
+ right : 1em;
+ top : 1em;
+ bottom : 1em;
+}
+
+.force {
+ padding-right : 5in;
+}
+
+#panel {
+ text-align : justify;
+ padding : 0.5em;
+ border-radius : 0.5em;
+ background : #ffffff;
+ max-height : 2.0em;
+ float : right;
+ overflow : hidden;
+}
+
+nav.expanded {
+ max-width : 95%;
+ -webkit-transition : max-width 0.5s ease-in-out;
+}
+
+nav.collapsed {
+ max-width : 12%;
+ -webkit-transition : max-width 0.5s ease-in-out;
+
+}
+
+nav.expanded > .button {
+ display : none;
+}
+
+nav.collapsed > .button {
+ display : inline-block;
+}
+
+nav.expanded > .option {
+ opacity : 1;
+ -webkit-transform : scale(1);
+ -webkit-transition : all 0.5s linear;
+}
+nav.collapsed > .option {
+ opacity : 0;
+ -webkit-transform : scale(0);
+ -webkit-transition : all 0.5s linear;
+}
+
+#dbg {
+ padding : 1em;
+ border-radius : 1em;
+ position : absolute;
+ top : 75%;
+ bottom : 1em;
+ left : 1em;
+ right : 1em;
+ background : #ffffff;
+}
+
+.measure {
+ position : absolute;
+ top : 0;
+ left : 0;
+ width : 320px;
+ background : green;
+}
diff --git a/examples/webkit/webkit-guide/css/anim_pulse.css b/examples/webkit/webkit-guide/css/anim_pulse.css
new file mode 100755
index 0000000000..4b850b9bc8
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_pulse.css
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+.force {
+ padding-left : 100%
+}
+
+nav {
+ text-align : justify;
+}
+
+nav > a {
+ background-size : contain;
+ background-repeat : no-repeat;
+}
+
+nav > a {
+ display : inline-block;
+ width : 2em;
+ height : 2em;
+}
+
+nav > a:nth-of-type(1) { background-image : url(../img/ic_fe_032.png); }
+nav > a:nth-of-type(2) { background-image : url(../img/ic_ni_032.png); }
+nav > a:nth-of-type(3) { background-image : url(../img/ic_he_032.png); }
+nav > a:nth-of-type(4) { background-image : url(../img/ic_na_032.png); }
+nav > a:nth-of-type(5) { background-image : url(../img/ic_zn_032.png); }
+nav > a:nth-of-type(6) { background-image : url(../img/ic_o_032.png); }
+
+h1,h2,h3 { margin-top : 0; }
+
+nav > a:target { -webkit-animation : pulse 1s infinite; }
+
+@-webkit-keyframes pulse {
+ 0% { opacity : 1.0 }
+ 50% { opacity : 0.7 }
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_skew.css b/examples/webkit/webkit-guide/css/anim_skew.css
new file mode 100755
index 0000000000..e44a633e96
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_skew.css
@@ -0,0 +1,186 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ padding : 1em;
+ font-family : "Helvetica";
+ font-weight : bold;
+}
+
+span {
+ background : #ffffff;
+ font-weight : bold;
+ cursor : pointer;
+}
+
+.items > div {
+ cursor : pointer;
+ background : #ffffff;
+ height : 2em;
+ padding : 0.5em 0.5em 0.0em 0.5em;
+ border-radius : 0.25em;
+ position : absolute;
+ left : 1em;
+ right : 1em;
+ -webkit-transition-property : -webkit-transform, top;
+ -webkit-transition-duration : 0.5s, 0.5s;
+ -webkit-transition-delay : 0s, 0.5s;
+ -webkit-transition-timing-function : ease-in-out;
+}
+
+.hide {
+ -webkit-transform-origin : bottom left;
+ -webkit-transform : skew(40deg) translate(140%,0em);
+}
+
+.items > div:after {
+ content : url(../img/icon_dismiss_x22.png);
+ float : right;
+}
+
+.row1 {
+ top : 3.5em;
+}
+.row2 {
+ top : 6.5em;
+}
+.row3 {
+ top : 9.5em;
+}
+.row4 {
+ top : 12.5em;
+}
+.row5 {
+ top : 15.5em;
+}
+.row6 {
+ top : 18.5em;
+}
+.row7 {
+ top : 21.5em;
+}
+.row8 {
+ top : 24.5em;
+}
+.row9 {
+ top : 27.5em;
+}
+.row10 {
+ top : 30.5em;
+}
+.row11 {
+ top : 33.5em;
+}
+.row12 {
+ top : 36.5em;
+}
+.row13 {
+ top : 39.5em;
+}
+.row14 {
+ top : 42.5em;
+}
+.row15 {
+ top : 45.5em;
+}
+
+.items > div {
+ padding-left : 3.0em;
+ color : #444444;
+ background-size : contain;
+ background-repeat : no-repeat;
+}
+
+.items > div[title='cat1'] {
+ background-image : url(../img/ic_fe_036.png);
+}
+
+.items > div[title='cat2'] {
+ background-image : url(../img/ic_na_036.png);
+}
+
+.items > div[title='cat3'] {
+ background-image : url(../img/ic_ni_036.png);
+}
+
+.items > div[title='cat4'] {
+ background-image : url(../img/ic_mg_036.png);
+}
+
+nav {
+ position : absolute;
+ background : #aaaaaa;
+ top : 0;
+ left : 0;
+ right : 0;
+ z-index : 10;
+ height : 2em;
+ text-align : center;
+ padding : 0.5em;
+}
+
+nav > div {
+ background-size : contain;
+ background-repeat : no-repeat;
+ display : inline-block;
+ width : 36px;
+ height : 36px;
+ margin-left : 0.25em;
+ margin-right : 0.25em;
+ background-image : -webkit-gradient(linear,center top,center bottom,from(#ffffff),to(#eeeeee));
+}
+
+nav > div {
+ background-image : url(../img/icon_list-all.png);
+}
+nav > .cat1 {
+ background-image : url(../img/ic_fe_036.png);
+}
+nav > .cat2 {
+ background-image : url(../img/ic_na_036.png);
+}
+nav > .cat3 {
+ background-image : url(../img/ic_ni_036.png);
+}
+nav > .cat4 {
+ background-image : url(../img/ic_mg_036.png);
+}
+
diff --git a/examples/webkit/webkit-guide/css/anim_slide.css b/examples/webkit/webkit-guide/css/anim_slide.css
new file mode 100755
index 0000000000..7997cc2c2b
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_slide.css
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* main layout */
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1 {
+ min-height : 1.5em;
+ background : #ffffff;
+ margin-left : 1em;
+ margin-right : 1em;
+ text-align : center;
+ font-size : 18px;
+ padding-top : 0.25em;
+ padding-bottom : 0.25em;
+ border-radius : 0.5em;
+}
+
+.panel {
+ position : absolute;
+ top : 0em;
+ bottom : 0em;
+ left : 0em;
+ right : 0em;
+}
+
+article {
+ background : #ffffff;
+ padding : 1em;
+ border-radius : 1em;
+ margin : 1em;
+}
+
+.panel > ul {
+ padding : 0em;
+ list-style-type : none;
+}
+.panel > ul > li {
+ background : #fff;
+ margin : 0.5em 1.0em 0.5em 1.0em;
+ padding : 0.5em;
+ display : block;
+ border-radius : 0.5em;
+}
+.panel > ul > li > a {
+ width : 100%;
+ display : block;
+ text-decoration : none;
+ text-align : justify;
+ color : #000000;
+}
+.panel > a {
+ background : #fff;
+ margin : 0 1.0em 1.0em 0em;
+ padding : 0.5em;
+}
+/* navigational hints */
+
+a.go_out {
+ background : transparent;
+ position : absolute;
+ top : 0.5em;
+ left : 1.2em;
+ content : url(../img/icon_drill-up_x32.png);
+ padding : 0.25em;
+ border-radius : 1em;
+ display : block;
+}
+
+.panel > ul > li > a:after {
+ text-align : right;
+ float : right;
+ font-size : 1em;
+ font-weight : bold;
+}
+.panel > ul > li > a:after {
+ -webkit-transform : translate(0, -0.5em);
+ content : url(../img/icon_drill-down_x32.png);
+}
+
+/* animations */
+#in:target {
+ -webkit-animation : slide_in 0.25s;
+}
+#out:target + .panel {
+ -webkit-animation : slide_out 0.25s;
+}
+@-webkit-keyframes slide_in {
+ from {
+ left : 80%;
+ right : -80%;
+ }
+ to {
+ left : 0em;
+ right : 0em;
+ }
+}
+@-webkit-keyframes slide_out {
+ from {
+ left : -80%;
+ right : 80%;
+ }
+ to {
+ left : 0em;
+ right : 0em;
+ }
+}
diff --git a/examples/webkit/webkit-guide/css/anim_tabbedSkew.css b/examples/webkit/webkit-guide/css/anim_tabbedSkew.css
new file mode 100755
index 0000000000..1c03e48966
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/anim_tabbedSkew.css
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+section {
+ background : #ffffff;
+ position : absolute;
+ left : 1em;
+ right : 1em;
+ top : 1em;
+ min-height : 60%;
+ padding : 1.0em;
+ border-radius : 0.5em;
+}
+
+nav {
+ text-align : right;
+ width : 3.5em;
+ height : 4em;
+ float : right;
+}
+
+nav > a {
+ border-radius : 0.25em;
+ width : 1em;
+ height : 1em;
+ text-align : center;
+ font-weight : bold;
+ font-size : 2em;
+ text-decoration : none;
+ color : black;
+ position : relative;
+ background-size : contain;
+ display : block;
+}
+
+nav > a:nth-of-type(1) {
+ margin-bottom : 0.1em;
+ background-image : url(../img/ic_he_032.png);
+ -webkit-transform : skew(-30deg);
+}
+
+nav > a:nth-of-type(2) {
+ background-image : url(../img/ic_o_032.png);
+ -webkit-transform : skew(30deg);
+}
+
+nav > a:nth-of-type(3) {
+ background-image : url(../img/ic_na_032.png);
+ -webkit-transform : rotate(-60deg) skew(-30deg) translate(1.7em, -1px);
+}
+
+article {
+ display : none;
+ margin-bottom : 4em;
+}
+
+article:target {
+ display : block;
+}
+
+h3 + div {
+ display : inline-block;
+ float : right;
+ width : 12px;
+ height : 3em;
+}
+
+h1,h2,h3,h4 {
+ margin-top : 0.5em;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_backgrounds.css b/examples/webkit/webkit-guide/css/css3_backgrounds.css
new file mode 100755
index 0000000000..c2a3a300e0
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_backgrounds.css
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+ background : #aaaaaa;
+}
+
+h1,h2,h3,h4 {
+ background : #ffffff;
+ text-align : center;
+ margin : 0.5em;
+ padding : 0.5em;
+ border-radius : 0.5em;
+}
+
+.accordion {
+ margin : 0.5em 0.5em 6em 0.5em;
+ border-radius : 0.5em;
+ border : thin solid #aaa;
+ background : #ffffff;
+ overflow : hidden;
+ padding : 1.0em 0.5em 1.0em 0.5em;
+
+}
+
+.accordion > dt {
+ cursor : pointer;
+ border-top : thin solid #aaa;
+ border-radius : 0.5em;
+ padding : 0.5em 0.5em 0.5em 2.5em;
+ font-weight : bold;
+ background-size : auto;
+ background-image : url(../img/icon_head-collapsed_x13.png);
+ background-repeat : no-repeat;
+ background-position : 12px 12px;
+}
+
+.accordion > dt:first-of-type {
+ border-top : none;
+}
+
+.accordion > dt.selected {
+ background-image : url(../img/icon_head-expanded_x13.png) , url(../img/gradient.jpg);
+ background-repeat : no-repeat , repeat-x;
+ background-position : 12px 12px , 0 0;
+ margin-bottom : 0em;
+}
+
+dt + dd {
+ max-height : 0%;
+ margin : 0;
+ opacity : 0;
+ padding : 0.5em;
+ overflow-y : hidden;
+ max-height : 0;
+ -webkit-transform : scaleY(0);
+ -webkit-transition : all 0.5s linear;
+}
+
+dt.selected + dd {
+ -webkit-transform : scaleY(1);
+ -webkit-transform-origin : center;
+ max-height : 1000px;
+ -webkit-transition : all 0.5s linear;
+ opacity : 1;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_border-img.css b/examples/webkit/webkit-guide/css/css3_border-img.css
new file mode 100755
index 0000000000..1293e2e27c
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_border-img.css
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+.fruit {
+ padding : 2.5em;
+ -webkit-border-image : url(../img/border-frame.png) 2 stretch stretch;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_grad-radial.css b/examples/webkit/webkit-guide/css/css3_grad-radial.css
new file mode 100755
index 0000000000..7799153dbd
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_grad-radial.css
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 70%;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_gradientBack.css b/examples/webkit/webkit-guide/css/css3_gradientBack.css
new file mode 100755
index 0000000000..48f9d68633
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_gradientBack.css
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+}
+
+section {
+ position : absolute;
+ top : 0.0em;
+ left : 0.0em;
+ right : 0.0em;
+ background : #aaaaaa;
+ background : -webkit-gradient(linear, center top, center bottom, from(#dddddd), to(#777777) );
+ padding : 1em;
+}
+
+article {
+ background : #ffffff;
+ padding : 1em;
+ border-radius : 0.5em;
+ border : thin #aaaaaa solid;
+ margin-bottom : 12em;
+}
+
+h1, h2, h3, h4 {
+ text-align : center;
+ margin-top : 0.5em;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_gradientBackStop.css b/examples/webkit/webkit-guide/css/css3_gradientBackStop.css
new file mode 100755
index 0000000000..0fbaf526ef
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_gradientBackStop.css
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+}
+
+section {
+ position : absolute;
+ top : 0.0em;
+ left : 0.0em;
+ right : 0.0em;
+ background : #aaaaaa;
+ background : -webkit-gradient(linear, center top, center bottom, from(#777777), color-stop(50%,#dddddd), to(#777777) );
+ padding : 1em;
+}
+
+article {
+ background : #ffffff;
+ padding : 1em;
+ border-radius : 0.5em;
+ border : thin #aaaaaa solid;
+ margin-bottom : 12em;
+}
+
+h1, h2, h3, h4 {
+ text-align : center;
+ margin-top : 0.5em;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_gradientButton.css b/examples/webkit/webkit-guide/css/css3_gradientButton.css
new file mode 100755
index 0000000000..6d0c9f77c8
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_gradientButton.css
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #ffffff;
+}
+
+article {
+ background : #ffffff;
+ position : absolute;
+ margin : 0;
+ left : 0;
+ right : 0;
+ top : 0;
+ bottom : 0;
+}
+
+ul {
+ font-weight : bold;
+ padding : 0;
+ list-style : none;
+ margin : 0.5em 0.5em 6em 0.5em;
+}
+
+ul > li {
+ margin-bottom : 0.5em;
+}
+
+ul > li > a {
+ padding : 0.5em;
+ display : block;
+ text-decoration : none;
+ color : #000000;
+ border : thin #aaaaaa solid;
+ border-radius : 0.5em;
+ background : #dddddd;
+ background : -webkit-gradient(linear, center top, center bottom,
+ from(#cccccc), to(#ffffff) );
+}
+
+ul > li > a:active {
+ color : #ffffff;
+ background : #ffffff;
+ background : -webkit-gradient(linear, center top, center bottom,
+ from(#dddddd), to(#444444) );
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_mask-grad.css b/examples/webkit/webkit-guide/css/css3_mask-grad.css
new file mode 100755
index 0000000000..24f0b227a7
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_mask-grad.css
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+ background : #ffffff;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+img {
+ -webkit-mask-box-image : -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
+ border-radius : 0.25em;
+ margin : 0.1em;
+}
+
+img.select {
+ -webkit-mask-box-image : none;
+ -webkit-box-shadow : 0.2em 0.2em 0.4em #aaaaaa;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_mask-img.css b/examples/webkit/webkit-guide/css/css3_mask-img.css
new file mode 100755
index 0000000000..0203d814fc
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_mask-img.css
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+ background : #333333;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+img {
+ position : absolute;
+ left : 5%;
+ top : 5%;
+ height : 90%;
+ width : 90%;
+ -webkit-mask-box-image : url(../img/mask.png) 5% stretch;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_multicol.css b/examples/webkit/webkit-guide/css/css3_multicol.css
new file mode 100755
index 0000000000..3c07f8b604
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_multicol.css
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ font-family : sans-serif;
+ background : #aaaaaa;
+}
+
+section {
+ bottom : 0;
+ left : 0;
+ top : 12%;
+ right : 0;
+ position : absolute;
+ padding-bottom : 6em;
+}
+
+article {
+ border-radius : 1em;
+ margin : 1em;
+ padding : 1em;
+ background : #ffffff;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+ margin-top : 0.0em;
+}
+
+nav.ad {
+ width : 500%;
+ border : thin #aaaaaa solid;
+ background : #dddddd;
+ position : absolute;
+ top : 0%;
+ height : 10%;
+ column-count : 5;
+ column-width : 100%;
+ -webkit-animation : banner_scroll 30s infinite;
+}
+
+nav.ad > a {
+ width : 20%;
+ height : 100%;
+ display : inline-block;
+ text-align : center;
+ padding-top : 0.5em;
+ text-decoration : none;
+ font-weight : bold;
+ color : #000000;
+ font-size : larger;
+}
+
+nav.ad > a:nth-of-type(5n-0) { background : lightgreen; }
+nav.ad > a:nth-of-type(5n-1) { background : pink; }
+nav.ad > a:nth-of-type(5n-2) { background : plum; }
+nav.ad > a:nth-of-type(5n-3) { background : lightblue; }
+nav.ad > a:nth-of-type(5n-4) { background : lightcoral; }
+
+@-webkit-keyframes banner_scroll {
+ 0% { left : 0%; }
+ 18% { left : 0%; }
+ 20% { left : -100%; }
+ 38% { left : -100%; }
+ 40% { left : -200%; }
+ 58% { left : -200%; }
+ 60% { left : -300%; }
+ 78% { left : -300%; }
+ 80% { left : -400%; }
+ 95% { left : -400%; }
+ 100% { left : 0%; }
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_reflect.css b/examples/webkit/webkit-guide/css/css3_reflect.css
new file mode 100755
index 0000000000..1f2e4542e8
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_reflect.css
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+body > section {
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ margin-bottom : 10em;
+ min-height : 70%;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
+.nav > a {
+ display : inline-block;
+ width : 48px;
+ height : 48px;
+}
+
+body > section.main {
+ position : absolute;
+ left : 0em;
+ right : 0em;
+ top : 0em;
+ min-height : 50%;
+ border-radius : 0.5em;
+ background : #aaaaaa;
+ padding : 0;
+}
+
+section.main > article {
+ background : #ffffff;
+ padding : 1em;
+ margin : 1em 1em 10em 1em;
+ border-radius : 0.5em;
+}
+
+h1, h2, h3 {
+ color : #206ead;
+ margin-top : 0em;
+ text-align : center;
+ margin-bottom : 1em;
+ -webkit-box-reflect : below -0.25em -webkit-gradient(linear, center top, center bottom, from(transparent), color-stop(0.25, transparent), to(black));
+}
+
+.nav1 { background-image : url(../img/ic_he_032.png) }
+.nav2 { background-image : url(../img/ic_o_032.png) }
+.nav3 { background-image : url(../img/ic_ni_032.png) }
+.nav4 { background-image : url(../img/ic_fe_032.png) }
+.nav5 { background-image : url(../img/ic_na_032.png) }
+.nav6 { background-image : url(../img/ic_zn_032.png) }
+
+h1 { font-size : 1.5em; }
+h2 { font-size : 1.2em; }
+h3 { font-size : 1.0em; }
+
+figure {
+ display : block;
+ text-align : center;
+}
+
+figure > img {
+ width : 70%;
+ margin-bottom : 3em;
+ -webkit-box-reflect : below 0.25em -webkit-gradient(linear, center top, center bottom, from(transparent), color-stop(0.50, transparent), to(black));
+}
+
+p:first-line {
+ font-weight : bold;
+}
+
+p:first-letter {
+ font-size : 200%;
+ float : left;
+ padding-right : 0.1em;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_scroll.css b/examples/webkit/webkit-guide/css/css3_scroll.css
new file mode 100755
index 0000000000..ae37c34d1e
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_scroll.css
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background-color : #aaaaaa;
+ font-family : sans-serif;
+}
+
+h1,h2,h3,h4 {
+ margin-top : 0.5em;
+ font-size : 18px;
+ text-align : center;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1.0em 0.5em 6.0em 0.5em;
+ min-height : 50%;
+}
+
+pre {
+ font-weight : bold;
+ font-family : monospace;
+ padding : 1.0em 3em 1.0em 1.0em;
+ border : thin solid #aaaaaa;
+ border-radius : 1.5em;
+ overflow-x : auto;
+ background-image : -webkit-gradient(linear,left center,right center,from(#ffffff),to(#777777));
+}
+
+pre::-webkit-scrollbar {
+ height : 3em;
+}
+
+pre::-webkit-scrollbar-button:increment {
+ background-image : url(../img/icon_scroll-right.png);
+x background-size : contain;
+ background-repeat : no-repeat;
+ width : 3em;
+ height : 3em;
+}
+
+pre::-webkit-scrollbar-button:decrement {
+ background-image : url(../img/icon_scroll-left.png);
+ background-size : contain;
+ background-repeat : no-repeat;
+ width : 3em;
+ height : 3em;
+}
+
+pre::-webkit-scrollbar-track {
+ display : none;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_sel-nth.css b/examples/webkit/webkit-guide/css/css3_sel-nth.css
new file mode 100755
index 0000000000..aa1e04b52a
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_sel-nth.css
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+img {
+ position : absolute;
+ width : 48px;
+ height : 48px;
+ padding : 0.25em;
+ border : #ffffff medium solid;
+ border-radius : 0.5em;
+}
+
+/* columns */
+img:nth-of-type(4n-3) { left : 2% }
+img:nth-of-type(4n-2) { left : 27% }
+img:nth-of-type(4n-1) { left : 52% }
+img:nth-of-type(4n-0) { left : 77% }
+
+/* rows */
+img:nth-of-type(n) { top : 5% }
+img:nth-of-type(n+5) { top : 20% }
+img:nth-of-type(n+9) { top : 35% }
+img:nth-of-type(n+13) { top : 50% }
+img:nth-of-type(n+17) { top : 65% }
+img:nth-of-type(n+21) { top : 80% }
+
diff --git a/examples/webkit/webkit-guide/css/css3_shadow.css b/examples/webkit/webkit-guide/css/css3_shadow.css
new file mode 100755
index 0000000000..d2f3040a4a
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_shadow.css
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+body > section {
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ margin-bottom : 10em;
+ min-height : 70%;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
+.nav > a {
+ display : inline-block;
+ width : 48px;
+ height : 48px;
+}
+
+nav > a:active {
+ -webkit-transform : scale(0.8);
+}
+
+h1, h2 {
+ margin-top : 0em;
+ font-size : 18px;
+ text-align : center;
+}
+
+h2 {
+ border-top : solid thin #aaaaaa;
+}
+
+body > section.main {
+ position : absolute;
+ left : 0em;
+ right : 0em;
+ top : 5em;
+ min-height : 50%;
+ border-radius : 0.5em;
+ background : #aaaaaa;
+ padding : 0;
+}
+
+section.main > article {
+ background : #ffffff;
+ padding : 1em;
+ margin : 1em 1em 10em 1em;
+ border-radius : 0.5em;
+}
+
+section.nav {
+ z-index : 10;
+ border-radius : 0;
+ background : #aaaaaa;
+ background : transparent;
+ position : absolute;;
+ padding : 1em;
+ top : 0;
+ right : 0.0em;
+ left : 0.0em;
+}
+
+nav {
+ padding : 0.5em;
+ border-radius : 0.5em;
+ background : #ffffff;
+ top : 10px;
+ text-align : justify;
+ height : 36px;
+ overflow : hidden;
+}
+
+nav > a {
+ display : inline-block;
+ background-repeat : no-repeat;
+ height : 36px;
+ width : 36px;
+}
+
+#force_justify {
+ padding-left : 100%;
+}
+
+.nav1 { background-image : url(../img/ic_he_032.png) }
+.nav2 { background-image : url(../img/ic_o_032.png) }
+.nav3 { background-image : url(../img/ic_ni_032.png) }
+.nav4 { background-image : url(../img/ic_fe_032.png) }
+.nav5 { background-image : url(../img/ic_na_032.png) }
+.nav6 { background-image : url(../img/ic_zn_032.png) }
+
+nav {
+ -webkit-box-shadow : 0.5em 0.5em #777777;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_shadowBlur.css b/examples/webkit/webkit-guide/css/css3_shadowBlur.css
new file mode 100755
index 0000000000..f44892735d
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_shadowBlur.css
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+body > section {
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ margin-bottom : 10em;
+ min-height : 70%;
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
+.nav > a {
+ display : inline-block;
+ width : 48px;
+ height : 48px;
+}
+
+h1, h2 {
+ margin-top : 0em;
+ font-size : 18px;
+ text-align : center;
+}
+
+h2 {
+ border-top : solid thin #aaaaaa;
+}
+
+body > section.main {
+ position : absolute;
+ left : 0em;
+ right : 0em;
+ top : 5em;
+ min-height : 50%;
+ border-radius : 0.5em;
+ background : #aaaaaa;
+ padding : 0;
+}
+
+section.main > article {
+ background : #ffffff;
+ padding : 1em;
+ margin : 1em 1em 10em 1em;
+ border-radius : 0.5em;
+}
+
+section.nav {
+ z-index : 10;
+ border-radius : 0;
+ background : #aaaaaa;
+ background : transparent;
+ position : absolute;;
+ padding : 1em;
+ top : 0;
+ right : 0.0em;
+ left : 0.0em;
+}
+
+nav {
+ padding : 0.5em;
+ border-radius : 0.5em;
+ background : #ffffff;
+ top : 10px;
+ text-align : justify;
+ height : 36px;
+ overflow : hidden;
+}
+
+nav > a {
+ display : inline-block;
+ background-repeat : no-repeat;
+ height : 36px;
+ width : 36px;
+}
+
+nav > a:active {
+ -webkit-transform : scale(0.8);
+}
+
+#force_justify {
+ padding-left : 100%;
+}
+
+.nav1 { background-image : url(../img/ic_he_032.png) }
+.nav2 { background-image : url(../img/ic_o_032.png) }
+.nav3 { background-image : url(../img/ic_ni_032.png) }
+.nav4 { background-image : url(../img/ic_fe_032.png) }
+.nav5 { background-image : url(../img/ic_na_032.png) }
+.nav6 { background-image : url(../img/ic_zn_032.png) }
+
+nav {
+ -webkit-box-shadow : 0.5em 0.5em 0.5em #444444;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_text-overflow.css b/examples/webkit/webkit-guide/css/css3_text-overflow.css
new file mode 100755
index 0000000000..ba491c41ae
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_text-overflow.css
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+.accordion {
+ border : #777777 solid thin;
+ padding : 0.0em;
+ border-radius : 0.5em;
+ list-style : none;
+}
+
+.accordion > li {
+ padding : 0.5em;
+ border-bottom : #777777 solid thin;
+ white-space : nowrap;
+ max-height : 1.5em;
+ overflow : hidden;
+ text-overflow : clip;
+ text-overflow : ellipsis;
+ text-overflow : ellipsis-word;
+ -webkit-transition : max-height 1s ease-in-out;
+}
+
+.accordion > li:last-of-type {
+ border-bottom : none;
+}
+
+.accordion > li.selected {
+ -webkit-transition : max-height 1s ease-in-out;
+ max-height : 100em;
+ white-space : normal;
+ font-weight : normal;
+}
+
+.accordion > li.selected:first-line {
+ font-weight : bold;
+}
+
+.accordion > li.selected:first-letter {
+ font-size : 200%;
+ float : left;
+ padding-right : 0.1em;
+}
+
+.dismiss {
+ content : url(../img/icon_dismiss.png);
+}
+
+.accordion > li > .dismiss {
+ display : none;
+}
+
+.accordion > li.selected > .dismiss {
+ display : block;
+ float : right;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_text-shadow.css b/examples/webkit/webkit-guide/css/css3_text-shadow.css
new file mode 100755
index 0000000000..9f06662c95
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_text-shadow.css
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+ text-shadow : 0.20em 0.20em 0.20em #999;
+ color : #206ead;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
diff --git a/examples/webkit/webkit-guide/css/css3_text-stroke.css b/examples/webkit/webkit-guide/css/css3_text-stroke.css
new file mode 100755
index 0000000000..4116de8223
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/css3_text-stroke.css
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+h1,h2,h3,h4 {
+ margin-top : 0.5em;
+ text-align : center;
+}
+
+h1 {
+ -webkit-text-stroke : 2px #000000;
+ font-size : 40px;
+}
+
+h1, h2, h3 {
+ color : #206ead;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
diff --git a/examples/webkit/webkit-guide/css/form_tapper.css b/examples/webkit/webkit-guide/css/form_tapper.css
new file mode 100755
index 0000000000..75142b5b19
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/form_tapper.css
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* MOBILE UI */
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+body > section {
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ margin : 1em 1em 10em 1em;
+ min-height : 70%
+}
+
+h1, h2 {
+ margin-top : 1em;
+ font-size : smaller;
+ text-align : center;
+ padding-top : 1em;
+}
+
+h2 {
+ border-top : solid thin #dddddd;
+}
+
+/* FORM */
+
+form {
+ font-weight : bold;
+ font-size : small;
+}
+
+input[type=radio],
+input[type=checkbox] {
+ -webkit-appearance : button;
+ float : right;
+ margin-bottom : -2em;
+ opacity : 0;
+}
+
+label,
+input[type=radio],
+input[type=checkbox] {
+ width : 90%;
+ display : block;
+ padding : 0.5em;
+ height : 2em;
+}
+
+label {
+ padding-top : 0.5em;
+ border : medium solid #aaaaaa;
+ border-radius : 1.0em;
+}
+
+input[type=radio]:checked + label,
+input[type=checkbox]:checked + label {
+ border : medium solid green;
+}
+
+input[type=radio]:checked + label:after,
+input[type=checkbox]:checked + label:after {
+ float : right;
+ padding-right : 0.5em;
+ content : url(../img/icon_check_x24green.png);
+}
+
diff --git a/examples/webkit/webkit-guide/css/form_toggler.css b/examples/webkit/webkit-guide/css/form_toggler.css
new file mode 100755
index 0000000000..224053f834
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/form_toggler.css
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* MOBILE UI */
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+body > section {
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ margin : 1em 1em 10em 1em;
+ min-height : 70%
+}
+
+h1, h2 {
+ margin-top : 1em;
+ font-size : smaller;
+ text-align : center;
+ padding-top : 1em;
+}
+
+h2 {
+ border-top : solid thin #dddddd;
+}
+
+ /* FORM */
+
+form
+{
+ line-height : 250%;
+ font-weight : bold;
+ font-size : small;
+}
+
+ /* DEFAULT INPUT */
+
+input[type=radio],
+input[type=checkbox]
+{
+ text-align : right;
+ padding-top : 0.1em;
+ text-transform : uppercase;
+ float : right;
+ -webkit-appearance : button;
+ border : 0.25em #aaaaaa solid;
+ background : #aaaaaa;
+ background : -webkit-gradient(linear,center top,center bottom,from(#999999),to(#ffffff));
+ border-radius : 0.5em;
+ min-width : 6em;
+ height : 2em;
+ display : inline-block;
+}
+
+ /* CHECKED INPUT */
+
+input[type=radio]:checked,
+input[type=checkbox]:checked
+{
+ text-align : left;
+}
+
+ /* FLIPPED INPUT */
+
+input.invert
+{
+ text-align : left;
+}
+
+input.invert:checked
+{
+ text-align : right;
+}
+
+ /* DEFAULT TEXT */
+
+input[type=radio]:before,
+input[type=checkbox]:before
+{
+ color : #888888;
+ height : 1.4em;
+ display : inline-block;
+ background : pink;
+ background : -webkit-gradient(linear,center top,center bottom,from(pink),to(#ffffff));
+ min-width : 50%;
+ content : "off";
+ text-align : center;
+ font-weight : bold;
+ padding-left : 0.5em;
+ padding-right : 0.5em;
+ border-radius : 0.25em;
+}
+
+ /* CHECKED TEXT */
+
+input[type=radio]:checked:before,
+input[type=checkbox]:checked:before
+{
+ color : #ffffff;
+ content : "on";
+ background : #00aa00;
+ background : -webkit-gradient(linear,center top,center bottom,from(green),to(cyan));
+}
+
+ /* ALTERNATE DISPLAY */
+
+input.yn:before
+{
+ content : "no";
+}
+
+input.yn:checked:before
+{
+ content : "yes";
+}
+
+input.tf:before
+{
+ content : "false";
+}
+
+input.tf:checked:before
+{
+ content : "true";
+}
+
+ /* BINARY */
+
+input.binary {
+ display : inline-block;
+}
+
+input.binary:checked {
+ display : none;
+}
+
+input.binary:before {
+ background : #00aa00;
+ background : -webkit-gradient(linear,center top,center bottom,from(green),to(cyan));
+ color : #ffffff;
+}
+
+input.binary:nth-of-type(odd) {
+ text-align : left;
+}
+
+input.binary:nth-of-type(even) {
+ text-align : right;
+}
+
+ /* CUSTOM */
+
+input.ampm:nth-of-type(odd):before { content : "am"; }
+input.ampm:nth-of-type(even):before { content : "pm"; }
+
+input.sex:nth-of-type(odd):before { content : "male"; }
+input.sex:nth-of-type(even):before { content : "female"; }
+
+input.sex { width : 8em }
+
diff --git a/examples/webkit/webkit-guide/css/layout_link-fmt.css b/examples/webkit/webkit-guide/css/layout_link-fmt.css
new file mode 100755
index 0000000000..5a31aa0736
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/layout_link-fmt.css
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+p {
+ font-weight : normal;
+}
+
+a {
+ text-wrap : suppress;
+ -webkit-text-wrap : suppress;
+}
+
+article {
+ background : #ffffff;
+ position : absolute;
+ top : 1em;
+ left : 1em;
+ right : 1em;
+ padding : 1em;
+ border-radius : 1em;
+ margin-bottom : 2em;
+}
+
+ol {
+ padding-left : 1em;
+}
+
+ol.links {
+ margin-bottom : 1em;
+ border : #aaaaaa thin solid;
+ list-style : none;
+ padding-top : 0.5em;
+ padding-bottom : 0.5em;
+ padding-left : 0em;
+ border-radius : 1.0em;
+}
+
+ol.links > li {
+ min-height : 2em;
+ border-bottom : #aaaaaa thin solid;
+ padding-left : 0.5em;
+ padding-right : 0.5em;
+ padding-top : 0.5em;
+}
+
+ol.links > li:last-of-type {
+ border : none;
+}
+
+p a[href]:after {
+ -webkit-transform : scale(0.6);
+ -webkit-transform-origin : bottom;
+ padding-left : 0.25em;
+ padding-right : 0.0em;
+ display : inline-block;
+}
+
+a[href] {
+ text-decoration : none;
+}
+
+ol.links > li > a {
+ display : block;
+}
+
+ol.links a:after {
+ -webkit-transform : scale(0.8);
+ -webkit-transform-origin : top;
+}
+
+a[href^="http://"]:after, a[href^="https://"]:after {
+ content : url(../img/icon_link-external.png);
+}
+
+a[href^="mailto:"]:after { content : url(../img/icon_link-email.png); }
+
+a[href^="sms:"]:after { content : url(../img/icon_link-sms.png); }
+
+a[href^="tel:"]:after { content : url(../img/icon_link-tel.png); }
+
+a[href$=".doc"]:after { content : url(../img/icon_link-doc.png); }
+
+a[href$=".ppt"]:after { content : url(../img/icon_link-ppt.png); }
+
+a[href$=".rss"]:after,
+a[href$=".xml"]:after { content : url(../img/icon_link-rss.png); }
+
+a[href$=".pdf"]:after { content : url(../img/icon_link-pdf.png); }
+
+a[href$=".xls"]:after { content : url(../img/icon_link-xls.png); }
+
+ol.links a:after {
+ float : right;
+}
diff --git a/examples/webkit/webkit-guide/css/layout_tbl-keyhole.css b/examples/webkit/webkit-guide/css/layout_tbl-keyhole.css
new file mode 100755
index 0000000000..1205822e6d
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/layout_tbl-keyhole.css
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+}
+
+.mobile {
+ display : block;
+}
+
+.mobile > thead > th,
+.mobile > thead > tr {
+ display : none;
+}
+
+.mobile > tbody > tr {
+ display : none;
+ background : #ffffff;
+ padding : 0.5em;
+ padding-top : 0.5em;
+ border-radius : 0.25em;
+}
+
+.mobile > tbody > tr:target {
+ display : block;
+ border : medium solid #aaaaaa;
+}
+
+.mobile > tbody > tr:nth-of-type(1) {
+ padding-top : 0.5em;
+}
+
+.mobile td {
+ display : block;
+}
+
+.mobile td:before {
+ font-style : italic;
+ font-weight : bold;
+}
+
+.mobile td:nth-of-type(5n+1) {
+ font-weight : bold;
+ color : #206ead;
+}
+
+.mobile td:nth-of-type(5n+2):before {
+ content : 'Price: ';
+}
+.mobile td:nth-of-type(5n+3):before {
+ content : 'Location: ';
+}
+.mobile td:nth-of-type(5n+4):before {
+ content : 'Posted: ';
+}
+
+table th.nav {
+ display : none;
+}
+
+.mobile tbody th.nav {
+ display : block;
+ width : 36px;
+ float : right;
+}
+
+th.nav a {
+ display : inline-block;
+ width : 36px;
+ height : 36px;
+ background : #ffffff;
+ content : url(../img/icon_nav-up.png);
+ margin-bottom : 0.5em;
+}
+
+th.nav a:nth-of-type(even) {
+ -webkit-transform : rotate(180deg);
+}
+
+tr:first-of-type th.nav a:nth-of-type(odd),
+tr:last-of-type th.nav a:nth-of-type(even)
+{
+ content : url(../img/icon_dismiss.png);
+}
+
+tr th.nav a {
+ display : none;
+}
+
+tr:first-of-type th.nav a,
+tr:last-of-type th.nav a,
+tr:target th.nav a {
+ display : block;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 0.5em;
+ margin : 0.5em;
+ padding : 0.5em;
+}
+
+h1 {
+ margin-top : 0.5em;
+ text-align : center;
+ font-size : 18px;
+}
+
diff --git a/examples/webkit/webkit-guide/css/mob_condjs.css b/examples/webkit/webkit-guide/css/mob_condjs.css
new file mode 100755
index 0000000000..6e312926ec
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mob_condjs.css
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+#js {
+ background : pink;
+ padding : 0.5em;
+ border-radius : 0.5em;
+}
+#js, #design {
+ padding : 0.5em;
+ border-radius : 0.5em;
+}
+#js {
+ background : pink;
+}
+#design {
+ background : lightgreen;
+}
diff --git a/examples/webkit/webkit-guide/css/mob_mediaquery.css b/examples/webkit/webkit-guide/css/mob_mediaquery.css
new file mode 100755
index 0000000000..bbd0fbcc88
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mob_mediaquery.css
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+#design {
+ padding : 0.5em;
+ border-radius : 0.5em;
+ background : lightgreen;
+}
+
+#design {
+ background : lightgreen;
+}
diff --git a/examples/webkit/webkit-guide/css/mobile.css b/examples/webkit/webkit-guide/css/mobile.css
new file mode 100755
index 0000000000..5b9332c3ce
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mobile.css
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ width : 100;
+}
+
+body > section {
+ border-radius : 1em;
+ background : #ffffff;
+ border-radius : 1em;
+ padding : 1em;
+ background : #ffffff;
+ min-height : 70%
+}
+
+.hidden {
+ display : none;
+}
+
+.active {
+ color : blue;
+ cursor : pointer;
+ text-decoration : none;
+}
+
+.nav > a {
+ display : inline-block;
+ width : 48px;
+ height : 48px;
+}
+
+h1, h2 {
+ margin-top : 1em;
+ font-size : smaller;
+ text-align : center;
+ padding-top : 1em;
+}
+
+h2 {
+ border-top : solid thin #dddddd;
+}
+
diff --git a/examples/webkit/webkit-guide/css/mq_desktop.css b/examples/webkit/webkit-guide/css/mq_desktop.css
new file mode 100755
index 0000000000..32d49bfa63
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mq_desktop.css
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+#design:before {
+ content : "CSS thinks you are viewing this page with a full desktop browser."
+}
+
diff --git a/examples/webkit/webkit-guide/css/mq_mobile.css b/examples/webkit/webkit-guide/css/mq_mobile.css
new file mode 100755
index 0000000000..f1e87f67ce
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mq_mobile.css
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+#design:before {
+ content : "CSS thinks you are viewing this page with a non-touch mobile browser."
+}
diff --git a/examples/webkit/webkit-guide/css/mq_touch.css b/examples/webkit/webkit-guide/css/mq_touch.css
new file mode 100755
index 0000000000..3d2a5b6cd5
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mq_touch.css
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background : #aaaaaa;
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+h1,h2,h3,h4 {
+ text-align : center;
+}
+
+section {
+ position : absolute;
+ top : 0;
+ left : 0;
+ right : 0;
+ bottom : 0;
+}
+
+article {
+ background : #ffffff;
+ border-radius : 1.0em;
+ padding : 1.0em;
+ margin : 1em;
+ min-height : 50%;
+}
+
+#design:before {
+ content : "CSS thinks you are viewing this page with a touch-based mobile browser."
+}
diff --git a/examples/webkit/webkit-guide/css/mqlayout_desktop.css b/examples/webkit/webkit-guide/css/mqlayout_desktop.css
new file mode 100755
index 0000000000..0875732145
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mqlayout_desktop.css
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* Desktop UI */
+
+body {
+ font-family : sans-serif;
+ font-weight : bold;
+ min-width : 60em;
+}
+
+nav, body > section, header, footer {
+ border-radius : 0.5em;
+ padding : 0.5em;
+}
+
+nav, section {
+ min-height : 30em;
+}
+
+header {
+ background-color : pink;
+ height : 3em;
+ margin-bottom : 1em;
+}
+
+section#main {
+ background-color : lightgreen;
+ float : left;
+ margin-bottom : 1em;
+ margin-left : 2%;
+ min-width : 60%;
+}
+
+nav {
+ background-color : lightblue;
+ float : left;
+ margin-bottom : 1em;
+ width : 15%;
+}
+
+section#sidebar {
+ background-color : plum;
+ float : left;
+ margin-bottom : 1em;
+ margin-left : 2%;
+ width : 15%;
+}
+
+footer {
+ background-color : gold;
+ clear : both;
+ height : 3em;
+}
+
diff --git a/examples/webkit/webkit-guide/css/mqlayout_mobile.css b/examples/webkit/webkit-guide/css/mqlayout_mobile.css
new file mode 100755
index 0000000000..dcd4943749
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mqlayout_mobile.css
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* Mobile UI */
+
+body {
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+nav, body > section, header, footer {
+ padding : 0.5em;
+}
+
+header {
+ display : none;
+}
+
+section#main {
+ background-color : lightgreen;
+ margin-bottom : 1em;
+}
+
+nav:after {
+ float : right;
+ content : '[ICON]';
+}
+
+nav:before {
+ content : 'SIMPLE ';
+}
+
+nav {
+ background-color : lightblue;
+ margin-bottom : 1em;
+}
+
+section#sidebar {
+ display : none;
+}
+
+footer {
+ background-color : gold;
+}
+
diff --git a/examples/webkit/webkit-guide/css/mqlayout_touch.css b/examples/webkit/webkit-guide/css/mqlayout_touch.css
new file mode 100755
index 0000000000..78ed1741c3
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/mqlayout_touch.css
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+/* Touch UI */
+
+body {
+ font-family : sans-serif;
+ font-weight : bold;
+}
+
+nav, body > section, header, footer {
+ border-radius : 0.5em;
+ padding : 0.5em;
+}
+
+header {
+ background-color : pink;
+ margin-bottom : 1em;
+ float : left;
+ width : 30%;
+ height : 3em;
+}
+
+section#main {
+ background-color : lightgreen;
+ margin-bottom : 1em;
+ min-height : 20em;
+}
+
+nav:before {
+ content : 'TOUCH ';
+}
+
+nav {
+ background-color : lightblue;
+ margin-bottom : 1em;
+ margin-left : 40%;
+ max-width : 60%;
+ height : 3em;
+}
+
+section#sidebar {
+ display : none;
+}
+
+footer {
+ background-color : gold;
+}
+
diff --git a/examples/webkit/webkit-guide/css/storage.css b/examples/webkit/webkit-guide/css/storage.css
new file mode 100755
index 0000000000..a1f1a13921
--- /dev/null
+++ b/examples/webkit/webkit-guide/css/storage.css
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+
+body {
+ background-color : #aaaaaa;
+ font-family : sans-serif;
+ padding: 1em;
+}
+
+body.off > h1 {
+ background-color : pink;
+ background-image : url(../img/offline.png), -webkit-gradient(linear,center top,center bottom,from(#ffffff),to(#ffffff))
+;
+}
+
+body.on > h1 {
+ background-color : lightgreen;
+ background-image : url(../img/online.png), -webkit-gradient(linear,center top,center bottom,from(#ffffff),to(#ffffff))
+;
+}
+
+body.unknown > h1 {
+ background-image : url(../img/offline_idle.png), -webkit-gradient(linear,center top,center bottom,from(#ffffff),to(#ffffff));
+}
+
+
+h1 {
+ background-color : #ffffff;
+ background-repeat : no-repeat;
+ background-position : 0.5em center, 0 0;
+ height : 1.25em;
+ border-radius : 0.5em;
+ margin : 0.0em;
+ padding : 0.5em;
+ text-align : center;
+ font-size : 18px;
+}
+
+form.show {
+ display : block;
+ z-index : 99;
+}
+
+form.hide {
+ display : none;
+}
+
+#cred {
+ background : #ffffff;
+ padding : 1em;
+ border-radius : 1.0em;
+ position : absolute;
+ left : 1.0em;;
+ right : 1.0em;;
+ top : 1.0em;;
+ bottom : 1.0em;;
+}
+
+#cred > input, #email > input {
+ height : 2.0em;
+ width : 95%;
+ border-radius : 0.5em;
+ padding-left : 0.5em;
+}
+
+#cred > img {
+ float : right;
+}
+
+#cred > div:first-of-type {
+ margin-top : 2em;
+}
+
+#cred > div, #email > div {
+ font-weight : bold;
+ margin : 0.5em;
+}
+
+#cred > input[type='submit'] {
+ background : lightgreen;
+ font-weight : bold;
+}
+
+#cred > input[type='submit']:active {
+ background : #777777;
+ color : #ffffff;
+}
+
+#cred > input.validate:invalid {
+ background : pink;
+}
+
+#cred > input.validate:invalid:after {
+ content : "need!";
+}
+
+#cred > input {
+ background : #ffffff;
+ -webkit-transition : all 1s linear;
+}
+
+#openform {
+ float : right;
+}
+
+#email {
+ background : #ffffff;
+ min-height : 6em;
+ margin-top : 1em;
+ border-radius : 0.5em;
+ padding : 0.5em;
+}
+
+textarea {
+ min-height : 10em;
+ width : 95%;
+ border-radius : 0.5em;
+}
+
diff --git a/examples/webkit/webkit-guide/css3_backgrounds.htm b/examples/webkit/webkit-guide/css3_backgrounds.htm
new file mode 100644
index 0000000000..0739830125
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_backgrounds.htm
@@ -0,0 +1,87 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Accordion Tabs</title>
+<link href='css/css3_backgrounds.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<h3>Accordion Tabs</h3>
+<dl class="accordion">
+<dt>Option 1</dt>
+<dd>
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo consequat.
+</dd>
+<dt>Option 2</dt>
+<dd>
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet,
+consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
+labore et dolore magna aliqua.
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo consequat.
+</dd>
+<dt>Option 3</dt>
+<dd>
+Lorem ipsum dolor sit amet, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat.
+</dd>
+<dt>Option 4</dt>
+<dd>
+Lorem ipsum dolor sit amet, sed do eiusmod tempor incididunt ut labore
+et dolore magna aliqua. Ut enim ad minim veniam, consectetur
+adipisicing elit, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo consequat. Consectetur adipisicing elit, ut
+enim ad minim veniam, sed do eiusmod tempor incididunt ut labore et
+dolore magna aliqua.
+</dd>
+</dl>
+<script src="js/css3_backgrounds.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
+
diff --git a/examples/webkit/webkit-guide/css3_border-img.htm b/examples/webkit/webkit-guide/css3_border-img.htm
new file mode 100644
index 0000000000..b991104f86
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_border-img.htm
@@ -0,0 +1,78 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>border-image</title>
+<link href='css/css3_border-img.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>border-image</h3>
+
+<p>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante.
+</p>
+
+<div class="fruit">
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus.
+
+</div>
+
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque.
+</p>
+
+</article>
+</section>
+<script src="js/css3_border-img.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_grad-radial.htm b/examples/webkit/webkit-guide/css3_grad-radial.htm
new file mode 100644
index 0000000000..3bbb7f0be1
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_grad-radial.htm
@@ -0,0 +1,61 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Radial Gradient</title>
+<link href='css/css3_grad-radial.css' type='text/css' rel='stylesheet'/>
+<style id="localStyles"></style>
+</head>
+<body>
+<section>
+<article id="main">
+<h3>Radial Gradient</h3>
+
+Touch within the main content area.
+
+</article>
+</section>
+<script src="js/css3_grad-radial.js">
+</script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_gradientBack.htm b/examples/webkit/webkit-guide/css3_gradientBack.htm
new file mode 100644
index 0000000000..1d025cf730
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_gradientBack.htm
@@ -0,0 +1,79 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Background Gradient</title>
+<link href='css/css3_gradientBack.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h4>Background Gradient</h4>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_gradientBackStop.htm b/examples/webkit/webkit-guide/css3_gradientBackStop.htm
new file mode 100644
index 0000000000..4558fe3466
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_gradientBackStop.htm
@@ -0,0 +1,92 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Background Gradient + stop-color</title>
+<link href='css/css3_gradientBackStop.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h4>Background Gradient<br/>with stop-color</h4>
+
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p><p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_gradientButton.htm b/examples/webkit/webkit-guide/css3_gradientButton.htm
new file mode 100644
index 0000000000..c765e45590
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_gradientButton.htm
@@ -0,0 +1,66 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Beveled Buttons</title>
+<link href='css/css3_gradientButton.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<article>
+<h3>Beveled Buttons</h3>
+<ul>
+<li><a href="#">Option 1</a></li>
+<li><a href="#">Option 2</a></li>
+<li><a href="#">Option 3</a></li>
+<li><a href="#">Option 4</a></li>
+<li><a href="#">Option 5</a></li>
+<li><a href="#">Option 6</a></li>
+<li><a href="#">Option 7</a></li>
+<li><a href="#">Option 8</a></li>
+<li><a href="#">Option 9</a></li>
+</ul>
+<p>&nbsp;</p>
+
+</article>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_mask-grad.htm b/examples/webkit/webkit-guide/css3_mask-grad.htm
new file mode 100644
index 0000000000..9014e5d5d9
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_mask-grad.htm
@@ -0,0 +1,66 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Webkit Masks</title>
+<link href='css/css3_mask-grad.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>Webkit Masks</h3>
+
+<img src="img/tnail_gal1.png"/>
+<img src="img/tnail_gal2.png"/>
+<img src="img/tnail_gal3.png"/>
+<img src="img/tnail_gal4.png"/>
+<img src="img/tnail_gal5.png"/>
+<img src="img/tnail_gal6.png"/>
+<img src="img/tnail_gal7.png"/>
+<img src="img/tnail_gal8.png"/>
+
+</article>
+</section>
+<script src="js/css3_mask-grad.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_mask-img.htm b/examples/webkit/webkit-guide/css3_mask-img.htm
new file mode 100644
index 0000000000..c102e96a1a
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_mask-img.htm
@@ -0,0 +1,56 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Webkit Masks</title>
+<link href='css/css3_mask-img.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<img src="img/gal3.jpg" width="240" height="360"/>
+</article>
+</section>
+<script src="js/css3_mask-img.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_multicol.htm b/examples/webkit/webkit-guide/css3_multicol.htm
new file mode 100644
index 0000000000..4b3fb6a792
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_multicol.htm
@@ -0,0 +1,91 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Animated Banners</title>
+<link href='css/css3_multicol.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>Animated Banners</h3>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+
+</article>
+<br/>
+<br/>
+<br/>
+<br/>
+<br/>
+<br/>
+<br/>
+<br/>
+</section>
+
+<nav class="ad">
+<a href="#">Item #1</a><a href="#">Item #2</a><a href="#">Item #3</a><a href="#">Item #4</a><a href="#">Item #5</a>
+</nav>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_reflect.htm b/examples/webkit/webkit-guide/css3_reflect.htm
new file mode 100644
index 0000000000..97e6ee20ce
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_reflect.htm
@@ -0,0 +1,100 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Webkit Reflections</title>
+<link href='css/css3_reflect.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="main">
+<article>
+<h1>Webkit Reflections</h1>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque.
+</p>
+
+<figure>
+<img src="img/land5.jpg">
+</figure>
+
+<p>Aliquam erat volutpat. Mauris tempor, urna at dignissim
+pellentesque, velit lacus dictum sem, non porttitor felis nulla nec
+risus. Donec a massa felis, a congue purus. Nullam et turpis
+diam. Aenean vestibulum egestas metus, eu sodales dolor venenatis
+quis. Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</p>
+
+<h2>Webkit Reflections</h2>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+<h3>Webkit Reflections</h3>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_scroll.htm b/examples/webkit/webkit-guide/css3_scroll.htm
new file mode 100644
index 0000000000..c2d3ea7b08
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_scroll.htm
@@ -0,0 +1,94 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Custom Scrollbars</title>
+<link href='css/css3_scroll.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>Custom Scrollbars</h3>
+
+<p>
+Unlike standard text, linebreaks cannot appear arbitrarily within
+blocks of code. Wide lines may be difficult to read within a
+narrow-screen mobile interface:
+</p>
+
+<pre>
+window.onload = function() {
+ var aside = document.querySelector('#related');
+ document.querySelector('#main').addEventListener('mouseup', function(event){
+ var thresholdDec = 0.5;
+ var totalHeight = event.currentTarget.scrollHeight;
+ var tapHeight = event.layerY;
+ var tapHeightDec = tapHeight / totalHeight;
+ var minHeight = 360;
+ if ( tapHeight < minHeight ) aside.className = '';
+ if (tapHeightDec > thresholdDec ) {
+ aside.className = 'visible';
+ }
+ else {
+ aside.className = '';
+ }
+ });
+};
+</pre>
+
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+
+</article>
+</section>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_sel-nth.htm b/examples/webkit/webkit-guide/css3_sel-nth.htm
new file mode 100644
index 0000000000..29f0605d05
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_sel-nth.htm
@@ -0,0 +1,80 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>CSS-only Grid Layout</title>
+<link href='css/css3_sel-nth.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+
+<img src="img/ic_ag_048.png"/>
+<img src="img/ic_al_048.png"/>
+<img src="img/ic_ar_048.png"/>
+<img src="img/ic_be_048.png"/>
+<img src="img/ic_b_048.png"/>
+<img src="img/ic_ca_048.png"/>
+<img src="img/ic_cl_048.png"/>
+<img src="img/ic_cu_048.png"/>
+<img src="img/ic_c_048.png"/>
+<img src="img/ic_fe_048.png"/>
+<img src="img/ic_f_048.png"/>
+<img src="img/ic_he_048.png"/>
+<img src="img/ic_h_048.png"/>
+<img src="img/ic_k_048.png"/>
+<img src="img/ic_li_048.png"/>
+<img src="img/ic_mg_048.png"/>
+<img src="img/ic_na_048.png"/>
+<img src="img/ic_ne_048.png"/>
+<img src="img/ic_ni_048.png"/>
+<img src="img/ic_n_048.png"/>
+<img src="img/ic_o_048.png"/>
+<img src="img/ic_pt_048.png"/>
+<img src="img/ic_si_048.png"/>
+<img src="img/ic_zn_048.png"/>
+
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_shadow.htm b/examples/webkit/webkit-guide/css3_shadow.htm
new file mode 100644
index 0000000000..7028047983
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_shadow.htm
@@ -0,0 +1,78 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Navigation Icon Feedback</title>
+<link href='css/css3_shadow.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section class="nav">
+<nav>
+<a class="nav1" href="#"></a>
+<a class="nav2" href="#"></a>
+<a class="nav3" href="#"></a>
+<a class="nav4" href="#"></a>
+<a class="nav5" href="#"></a>
+<a class="nav6" href="#"></a>
+<span id="force_justify">&nbsp;</span>
+</nav>
+</section>
+<section class="main">
+<article>
+<h1>Navigation Icon Feedback</h1>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl. Aenean elementum arcu
+sed nibh faucibus pellentesque. Aliquam erat volutpat. Mauris tempor,
+urna at dignissim pellentesque, velit lacus dictum sem, non porttitor
+felis nulla nec risus. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_text-overflow.htm b/examples/webkit/webkit-guide/css3_text-overflow.htm
new file mode 100644
index 0000000000..d56ac778b6
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_text-overflow.htm
@@ -0,0 +1,117 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>text-overflow</title>
+<link href='css/css3_text-overflow.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>text-overflow</h3>
+
+<ul class="accordion">
+<li id="l1">
+<div class="dismiss"></div>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus. Mauris tempor, urna at dignissim pellentesque, velit lacus
+dictum sem, non porttitor felis nulla nec risus.
+</li>
+<li id="l2">
+<div class="dismiss"></div>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante,
+id mollis risus lectus ornare nisl. Aenean elementum arcu sed nibh
+faucibus pellentesque. Aliquam erat volutpat. Donec a massa felis, a
+congue purus. Nullam et turpis diam. Aenean vestibulum egestas metus,
+eu sodales dolor venenatis quis. Aenean augue orci, facilisis et
+convallis ut, egestas at neque.
+</li>
+<li id="l3">
+<div class="dismiss"></div>
+Donec a massa felis, a congue purus. Nullam et turpis diam. Aenean
+vestibulum egestas metus, eu sodales dolor venenatis quis. Aenean
+augue orci, facilisis et convallis ut, egestas at neque. Lorem ipsum
+dolor sit amet, consectetur adipiscing elit. Donec feugiat gravida
+viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus ac
+tellus.
+</li>
+<li id="l4">
+<div class="dismiss"></div>
+Aenean vestibulum egestas metus, eu sodales dolor venenatis quis.
+Aenean augue orci, facilisis et convallis ut, egestas at neque.
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.
+Donec a massa felis, a congue purus.
+</li>
+<li id="l5">
+<div class="dismiss"></div>
+Nullam et turpis diam. Vivamus ipsum felis, cursus sed venenatis nec,
+tempus ac tellus. Lorem ipsum dolor sit amet, consectetur adipiscing
+elit. Donec a massa felis, a congue purus. Aenean vestibulum egestas
+metus, eu sodales dolor venenatis quis. Donec feugiat gravida
+viverra. Praesent luctus, risus eu vestibulum mollis, arcu mauris
+mollis ante, id mollis risus lectus ornare nisl.
+</li>
+<li id="l6">
+<div class="dismiss"></div>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.
+Aenean elementum arcu sed nibh faucibus pellentesque. Aliquam erat
+volutpat.
+Donec a massa felis, a congue purus.
+Aenean vestibulum egestas metus, eu sodales dolor venenatis quis.
+</li>
+<li id="l7">
+<div class="dismiss"></div>
+Donec feugiat gravida viverra. Praesent luctus, risus eu vestibulum
+mollis, arcu mauris mollis ante, id mollis risus lectus ornare nisl.
+Aliquam erat volutpat. Nullam et turpis diam. Aenean augue orci,
+facilisis et convallis ut, egestas at neque.
+</li>
+</ul>
+
+</article>
+</section>
+<script src="js/css3_text-overflow.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_text-shadow.htm b/examples/webkit/webkit-guide/css3_text-shadow.htm
new file mode 100644
index 0000000000..60e2d22471
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_text-shadow.htm
@@ -0,0 +1,74 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Text Shadow</title>
+<link href='css/css3_text-shadow.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h1>Text Shadow</h1>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus.
+</p>
+<h2>Subhead</h2>
+<p>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante,
+id mollis risus lectus ornare nisl. Aenean elementum arcu sed nibh
+faucibus pellentesque. Aliquam erat volutpat. Mauris tempor, urna at
+dignissim pellentesque, velit lacus dictum sem, non porttitor felis
+nulla nec risus. Donec a massa felis, a congue purus. Nullam et turpis
+diam.
+</p>
+<h3>Subhead</h3>
+<p>
+Aenean vestibulum egestas metus, eu sodales dolor venenatis
+quis. Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/css3_text-stroke.htm b/examples/webkit/webkit-guide/css3_text-stroke.htm
new file mode 100644
index 0000000000..25dfb1c4aa
--- /dev/null
+++ b/examples/webkit/webkit-guide/css3_text-stroke.htm
@@ -0,0 +1,74 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Text Stroke</title>
+<link href='css/css3_text-stroke.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h1>Text Stroke</h1>
+<p>
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus.
+</p>
+<h2>Subhead</h2>
+<p>
+Praesent luctus, risus eu vestibulum mollis, arcu mauris mollis ante,
+id mollis risus lectus ornare nisl. Aenean elementum arcu sed nibh
+faucibus pellentesque. Aliquam erat volutpat. Mauris tempor, urna at
+dignissim pellentesque, velit lacus dictum sem, non porttitor felis
+nulla nec risus. Donec a massa felis, a congue purus. Nullam et turpis
+diam.
+</p>
+<h3>Subhead</h3>
+<p>
+Aenean vestibulum egestas metus, eu sodales dolor venenatis
+quis. Aenean augue orci, facilisis et convallis ut, egestas at neque.
+</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/form_tapper.htm b/examples/webkit/webkit-guide/form_tapper.htm
new file mode 100644
index 0000000000..94751dc9a3
--- /dev/null
+++ b/examples/webkit/webkit-guide/form_tapper.htm
@@ -0,0 +1,74 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>CSS-only Tap Button Inputs</title>
+<link href='css/form_tapper.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<h1>CSS-only Tap Button Inputs</h1>
+<form>
+<h2>radio</h2>
+<input type="radio" name="radio_basic" value="one"/>
+<label>Option One</label>
+<br/>
+<input type="radio" name="radio_basic" value="two"/>
+<label>Option Two</label>
+<br/>
+<input type="radio" name="radio_basic" value="three"/>
+<label>Option Three</label>
+<h2>checkbox</h2>
+<input type="checkbox" name="checkbox_basic" value="one"/>
+<label>Option One</label>
+<br/>
+<input type="checkbox" name="checkbox_basic" value="two"/>
+<label>Option Two</label>
+<br/>
+<input type="checkbox" name="checkbox_basic" value="three"/>
+<label>Option Three</label>
+</form>
+</section>
+<script src="js/form_tapper.js"></script>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/form_toggler.htm b/examples/webkit/webkit-guide/form_toggler.htm
new file mode 100644
index 0000000000..f4b170253e
--- /dev/null
+++ b/examples/webkit/webkit-guide/form_toggler.htm
@@ -0,0 +1,140 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>CSS-only Toggle Button Inputs</title>
+<link href='css/form_toggler.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<h1>CSS-only Toggle Button Inputs</h1>
+<form>
+<h2>radio (default)</h2>
+<label>Option One</label>
+<input type="radio" name="radio_basic" value="one"/>
+<br/>
+<label>Option Two</label>
+<input type="radio" name="radio_basic" value="two"/>
+<br/>
+<label>Option Three</label>
+<input type="radio" name="radio_basic" value="three"/>
+<h2>checkbox (default)</h2>
+<input type="checkbox" name="checkbox_basic" value="one"/>
+<label>Option One</label>
+<br/>
+<input type="checkbox" name="checkbox_basic" value="two"/>
+<label>Option Two</label>
+<br/>
+<input type="checkbox" name="checkbox_basic" value="three"/>
+<label>Option Three</label>
+<h2>radio class="invert"</h2>
+<label>Option One</label>
+<input class="invert" type="radio" name="radio_invert" value="one"/>
+<br/>
+<label>Option Two</label>
+<input class="invert" type="radio" name="radio_invert" value="two"/>
+<br/>
+<label>Option Three</label>
+<input class="invert" type="radio" name="radio_invert" value="three"/>
+<h2>checkbox class="invert"</h2>
+<input class="invert" type="checkbox" name="checkbox_invert" value="one"/>
+<label>Option One</label>
+<br/>
+<input class="invert" type="checkbox" name="checkbox_invert" value="two"/>
+<label>Option Two</label>
+<br/>
+<input class="invert" type="checkbox" name="checkbox_invert" value="three"/>
+<label>Option Three</label>
+<h2>radio class="yn"</h2>
+<label>Option One</label>
+<input class="yn" type="radio" name="radio_yn" value="one"/>
+<br/>
+<label>Option Two</label>
+<input class="yn" type="radio" name="radio_yn" value="two"/>
+<br/>
+<label>Option Three</label>
+<input class="yn" type="radio" name="radio_yn" value="three"/>
+<h2>checkbox class="yn"</h2>
+<input class="yn" type="checkbox" name="checkbox_yn" value="one"/>
+<label>Option One</label>
+<br/>
+<input class="yn" type="checkbox" name="checkbox_yn" value="two"/>
+<label>Option Two</label>
+<br/>
+<input class="yn" type="checkbox" name="checkbox_yn" value="three"/>
+<label>Option Three</label>
+<h2>radio class="tf"</h2>
+<label>Option One</label>
+<input class="tf" type="radio" name="radio_tf" value="one"/>
+<br/>
+<label>Option Two</label>
+<input class="tf" type="radio" name="radio_tf" value="two"/>
+<br/>
+<label>Option Three</label>
+<input class="tf" type="radio" name="radio_tf" value="three"/>
+<h2>checkbox class="tf"</h2>
+<input class="tf" type="checkbox" name="checkbox_tf" value="one"/>
+<label>Option One</label>
+<br/>
+<input class="tf" type="checkbox" name="checkbox_tf" value="two"/>
+<label>Option Two</label>
+<br/>
+<input class="tf" type="checkbox" name="checkbox_tf" value="three"/>
+<label>Option Three</label>
+<h2>radio class="binary"</h2>
+<label>Time of Day</label>
+<input class="binary ampm" type="radio" name="radio_binary" value="am"/>
+<input class="binary ampm" type="radio" name="radio_binary" value="pm" checked/>
+<br/>
+<label>Sex</label>
+<input class="binary sex" type="radio" name="radio_sex" value="male" checked/>
+<input class="binary sex" type="radio" name="radio_sex" value="female"/>
+<br/>
+<br/>
+<p>(These use custom button values)</p>
+<br/>
+<br/>
+</form>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/img/border-frame.png b/examples/webkit/webkit-guide/img/border-frame.png
new file mode 100755
index 0000000000..7a0894cabc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/border-frame.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal1.jpg b/examples/webkit/webkit-guide/img/gal1.jpg
new file mode 100644
index 0000000000..8f9edcb2ca
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal1.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal2.jpg b/examples/webkit/webkit-guide/img/gal2.jpg
new file mode 100644
index 0000000000..a2301ef22f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal2.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal3.jpg b/examples/webkit/webkit-guide/img/gal3.jpg
new file mode 100644
index 0000000000..a768530a8c
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal3.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal4.jpg b/examples/webkit/webkit-guide/img/gal4.jpg
new file mode 100644
index 0000000000..96c00015c0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal4.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal5.jpg b/examples/webkit/webkit-guide/img/gal5.jpg
new file mode 100644
index 0000000000..6ec78fc43a
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal5.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal6.jpg b/examples/webkit/webkit-guide/img/gal6.jpg
new file mode 100644
index 0000000000..25eb95cb22
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal6.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal7.jpg b/examples/webkit/webkit-guide/img/gal7.jpg
new file mode 100644
index 0000000000..b9fda2fb9d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal7.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gal8.jpg b/examples/webkit/webkit-guide/img/gal8.jpg
new file mode 100644
index 0000000000..c23e2260c3
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gal8.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gradient.jpg b/examples/webkit/webkit-guide/img/gradient.jpg
new file mode 100755
index 0000000000..014386e275
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gradient.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/gray_icon_close.png b/examples/webkit/webkit-guide/img/gray_icon_close.png
new file mode 100755
index 0000000000..8e7450153e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/gray_icon_close.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ag_016.png b/examples/webkit/webkit-guide/img/ic_ag_016.png
new file mode 100755
index 0000000000..bb961cb393
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ag_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ag_032.png b/examples/webkit/webkit-guide/img/ic_ag_032.png
new file mode 100755
index 0000000000..edb051f50e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ag_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ag_036.png b/examples/webkit/webkit-guide/img/ic_ag_036.png
new file mode 100755
index 0000000000..e555e92071
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ag_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ag_048.png b/examples/webkit/webkit-guide/img/ic_ag_048.png
new file mode 100755
index 0000000000..d2d417da2e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ag_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_al_016.png b/examples/webkit/webkit-guide/img/ic_al_016.png
new file mode 100755
index 0000000000..0f1c0240fb
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_al_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_al_032.png b/examples/webkit/webkit-guide/img/ic_al_032.png
new file mode 100755
index 0000000000..5727a5104e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_al_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_al_036.png b/examples/webkit/webkit-guide/img/ic_al_036.png
new file mode 100755
index 0000000000..76382779b8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_al_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_al_048.png b/examples/webkit/webkit-guide/img/ic_al_048.png
new file mode 100755
index 0000000000..9671d86944
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_al_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ar_016.png b/examples/webkit/webkit-guide/img/ic_ar_016.png
new file mode 100755
index 0000000000..fa91e96dca
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ar_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ar_032.png b/examples/webkit/webkit-guide/img/ic_ar_032.png
new file mode 100755
index 0000000000..d899c41fdb
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ar_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ar_036.png b/examples/webkit/webkit-guide/img/ic_ar_036.png
new file mode 100755
index 0000000000..836593f4bc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ar_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ar_048.png b/examples/webkit/webkit-guide/img/ic_ar_048.png
new file mode 100755
index 0000000000..e1c77aca74
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ar_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_b_016.png b/examples/webkit/webkit-guide/img/ic_b_016.png
new file mode 100755
index 0000000000..a0ebdf7964
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_b_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_b_032.png b/examples/webkit/webkit-guide/img/ic_b_032.png
new file mode 100755
index 0000000000..f5571f2bb9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_b_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_b_036.png b/examples/webkit/webkit-guide/img/ic_b_036.png
new file mode 100755
index 0000000000..4aff7eb601
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_b_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_b_048.png b/examples/webkit/webkit-guide/img/ic_b_048.png
new file mode 100755
index 0000000000..b84434cec4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_b_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_be_016.png b/examples/webkit/webkit-guide/img/ic_be_016.png
new file mode 100755
index 0000000000..0297cd827d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_be_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_be_032.png b/examples/webkit/webkit-guide/img/ic_be_032.png
new file mode 100755
index 0000000000..5c5b9cd9e1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_be_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_be_036.png b/examples/webkit/webkit-guide/img/ic_be_036.png
new file mode 100755
index 0000000000..96ec4bb4ca
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_be_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_be_048.png b/examples/webkit/webkit-guide/img/ic_be_048.png
new file mode 100755
index 0000000000..afcdf183dd
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_be_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_c_016.png b/examples/webkit/webkit-guide/img/ic_c_016.png
new file mode 100755
index 0000000000..a3cc4cfadf
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_c_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_c_032.png b/examples/webkit/webkit-guide/img/ic_c_032.png
new file mode 100755
index 0000000000..404babecf1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_c_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_c_036.png b/examples/webkit/webkit-guide/img/ic_c_036.png
new file mode 100755
index 0000000000..78d71500d9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_c_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_c_048.png b/examples/webkit/webkit-guide/img/ic_c_048.png
new file mode 100755
index 0000000000..73462ad394
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_c_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ca_016.png b/examples/webkit/webkit-guide/img/ic_ca_016.png
new file mode 100755
index 0000000000..af4c37b0e5
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ca_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ca_032.png b/examples/webkit/webkit-guide/img/ic_ca_032.png
new file mode 100755
index 0000000000..6ac8db4ce6
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ca_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ca_036.png b/examples/webkit/webkit-guide/img/ic_ca_036.png
new file mode 100755
index 0000000000..19988c165d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ca_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ca_048.png b/examples/webkit/webkit-guide/img/ic_ca_048.png
new file mode 100755
index 0000000000..0349061038
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ca_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cl_016.png b/examples/webkit/webkit-guide/img/ic_cl_016.png
new file mode 100755
index 0000000000..e9b421e70c
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cl_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cl_032.png b/examples/webkit/webkit-guide/img/ic_cl_032.png
new file mode 100755
index 0000000000..f5968d5dfe
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cl_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cl_036.png b/examples/webkit/webkit-guide/img/ic_cl_036.png
new file mode 100755
index 0000000000..2a6721d780
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cl_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cl_048.png b/examples/webkit/webkit-guide/img/ic_cl_048.png
new file mode 100755
index 0000000000..f32981fe81
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cl_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cu_016.png b/examples/webkit/webkit-guide/img/ic_cu_016.png
new file mode 100755
index 0000000000..129f99ffd1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cu_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cu_032.png b/examples/webkit/webkit-guide/img/ic_cu_032.png
new file mode 100755
index 0000000000..a07933ea68
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cu_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cu_036.png b/examples/webkit/webkit-guide/img/ic_cu_036.png
new file mode 100755
index 0000000000..5eb6ed6363
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cu_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_cu_048.png b/examples/webkit/webkit-guide/img/ic_cu_048.png
new file mode 100755
index 0000000000..f21593cf78
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_cu_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_f_016.png b/examples/webkit/webkit-guide/img/ic_f_016.png
new file mode 100755
index 0000000000..ff2e3fb5f4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_f_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_f_032.png b/examples/webkit/webkit-guide/img/ic_f_032.png
new file mode 100755
index 0000000000..3424799317
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_f_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_f_036.png b/examples/webkit/webkit-guide/img/ic_f_036.png
new file mode 100755
index 0000000000..019b7032a6
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_f_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_f_048.png b/examples/webkit/webkit-guide/img/ic_f_048.png
new file mode 100755
index 0000000000..567d30310a
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_f_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_fe_016.png b/examples/webkit/webkit-guide/img/ic_fe_016.png
new file mode 100755
index 0000000000..e6d9b829b9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_fe_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_fe_032.png b/examples/webkit/webkit-guide/img/ic_fe_032.png
new file mode 100755
index 0000000000..f2b4e4b417
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_fe_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_fe_036.png b/examples/webkit/webkit-guide/img/ic_fe_036.png
new file mode 100755
index 0000000000..2aa81b5fec
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_fe_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_fe_048.png b/examples/webkit/webkit-guide/img/ic_fe_048.png
new file mode 100755
index 0000000000..b6914735d9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_fe_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_h_016.png b/examples/webkit/webkit-guide/img/ic_h_016.png
new file mode 100755
index 0000000000..957a1ffabe
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_h_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_h_032.png b/examples/webkit/webkit-guide/img/ic_h_032.png
new file mode 100755
index 0000000000..824620d4a2
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_h_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_h_036.png b/examples/webkit/webkit-guide/img/ic_h_036.png
new file mode 100755
index 0000000000..fba59a5d27
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_h_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_h_048.png b/examples/webkit/webkit-guide/img/ic_h_048.png
new file mode 100755
index 0000000000..f75822c3aa
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_h_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_he_016.png b/examples/webkit/webkit-guide/img/ic_he_016.png
new file mode 100755
index 0000000000..33fe83677f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_he_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_he_032.png b/examples/webkit/webkit-guide/img/ic_he_032.png
new file mode 100755
index 0000000000..425c525b69
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_he_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_he_036.png b/examples/webkit/webkit-guide/img/ic_he_036.png
new file mode 100755
index 0000000000..a976aece8b
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_he_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_he_048.png b/examples/webkit/webkit-guide/img/ic_he_048.png
new file mode 100755
index 0000000000..f8f9d4d853
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_he_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_k_016.png b/examples/webkit/webkit-guide/img/ic_k_016.png
new file mode 100755
index 0000000000..860bd62f96
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_k_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_k_032.png b/examples/webkit/webkit-guide/img/ic_k_032.png
new file mode 100755
index 0000000000..a14f2c65e9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_k_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_k_036.png b/examples/webkit/webkit-guide/img/ic_k_036.png
new file mode 100755
index 0000000000..49f19e6df0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_k_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_k_048.png b/examples/webkit/webkit-guide/img/ic_k_048.png
new file mode 100755
index 0000000000..a7515cd782
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_k_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_li_016.png b/examples/webkit/webkit-guide/img/ic_li_016.png
new file mode 100755
index 0000000000..c16d81a4bc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_li_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_li_032.png b/examples/webkit/webkit-guide/img/ic_li_032.png
new file mode 100755
index 0000000000..3a34f37066
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_li_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_li_036.png b/examples/webkit/webkit-guide/img/ic_li_036.png
new file mode 100755
index 0000000000..e5b97a7a2e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_li_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_li_048.png b/examples/webkit/webkit-guide/img/ic_li_048.png
new file mode 100755
index 0000000000..7b030e4cd7
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_li_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_mg_016.png b/examples/webkit/webkit-guide/img/ic_mg_016.png
new file mode 100755
index 0000000000..2606336415
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_mg_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_mg_032.png b/examples/webkit/webkit-guide/img/ic_mg_032.png
new file mode 100755
index 0000000000..2f9d03e6b0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_mg_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_mg_036.png b/examples/webkit/webkit-guide/img/ic_mg_036.png
new file mode 100755
index 0000000000..584078db84
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_mg_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_mg_048.png b/examples/webkit/webkit-guide/img/ic_mg_048.png
new file mode 100755
index 0000000000..8cd2f3acc7
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_mg_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_n_016.png b/examples/webkit/webkit-guide/img/ic_n_016.png
new file mode 100755
index 0000000000..90e8f9fec9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_n_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_n_032.png b/examples/webkit/webkit-guide/img/ic_n_032.png
new file mode 100755
index 0000000000..afeb47a105
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_n_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_n_036.png b/examples/webkit/webkit-guide/img/ic_n_036.png
new file mode 100755
index 0000000000..0b7a11deed
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_n_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_n_048.png b/examples/webkit/webkit-guide/img/ic_n_048.png
new file mode 100755
index 0000000000..c0d7c0699e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_n_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_na_016.png b/examples/webkit/webkit-guide/img/ic_na_016.png
new file mode 100755
index 0000000000..7888d0f9c0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_na_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_na_032.png b/examples/webkit/webkit-guide/img/ic_na_032.png
new file mode 100755
index 0000000000..801ddca50b
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_na_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_na_036.png b/examples/webkit/webkit-guide/img/ic_na_036.png
new file mode 100755
index 0000000000..a6878d45d7
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_na_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_na_048.png b/examples/webkit/webkit-guide/img/ic_na_048.png
new file mode 100755
index 0000000000..76adaf479c
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_na_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ne_016.png b/examples/webkit/webkit-guide/img/ic_ne_016.png
new file mode 100755
index 0000000000..64562fc2d5
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ne_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ne_032.png b/examples/webkit/webkit-guide/img/ic_ne_032.png
new file mode 100755
index 0000000000..fab5cd8fcb
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ne_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ne_036.png b/examples/webkit/webkit-guide/img/ic_ne_036.png
new file mode 100755
index 0000000000..41092bf3e7
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ne_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ne_048.png b/examples/webkit/webkit-guide/img/ic_ne_048.png
new file mode 100755
index 0000000000..4ec0db0806
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ne_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ni_016.png b/examples/webkit/webkit-guide/img/ic_ni_016.png
new file mode 100755
index 0000000000..9b88e368a2
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ni_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ni_032.png b/examples/webkit/webkit-guide/img/ic_ni_032.png
new file mode 100755
index 0000000000..fc4fcf3ebc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ni_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ni_036.png b/examples/webkit/webkit-guide/img/ic_ni_036.png
new file mode 100755
index 0000000000..9d527470bb
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ni_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_ni_048.png b/examples/webkit/webkit-guide/img/ic_ni_048.png
new file mode 100755
index 0000000000..b563c50361
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_ni_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_o_016.png b/examples/webkit/webkit-guide/img/ic_o_016.png
new file mode 100755
index 0000000000..a95460d457
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_o_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_o_032.png b/examples/webkit/webkit-guide/img/ic_o_032.png
new file mode 100755
index 0000000000..1d4864dded
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_o_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_o_036.png b/examples/webkit/webkit-guide/img/ic_o_036.png
new file mode 100755
index 0000000000..7f5dd02ed2
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_o_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_o_048.png b/examples/webkit/webkit-guide/img/ic_o_048.png
new file mode 100755
index 0000000000..7461a8e9e4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_o_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_pt_016.png b/examples/webkit/webkit-guide/img/ic_pt_016.png
new file mode 100755
index 0000000000..513eb97a30
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_pt_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_pt_032.png b/examples/webkit/webkit-guide/img/ic_pt_032.png
new file mode 100755
index 0000000000..1550c399c8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_pt_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_pt_036.png b/examples/webkit/webkit-guide/img/ic_pt_036.png
new file mode 100755
index 0000000000..7eec4d0ce4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_pt_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_pt_048.png b/examples/webkit/webkit-guide/img/ic_pt_048.png
new file mode 100755
index 0000000000..50dece6610
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_pt_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_si_016.png b/examples/webkit/webkit-guide/img/ic_si_016.png
new file mode 100755
index 0000000000..e639b683ae
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_si_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_si_032.png b/examples/webkit/webkit-guide/img/ic_si_032.png
new file mode 100755
index 0000000000..8657e6276f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_si_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_si_036.png b/examples/webkit/webkit-guide/img/ic_si_036.png
new file mode 100755
index 0000000000..ffe0ee27fc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_si_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_si_048.png b/examples/webkit/webkit-guide/img/ic_si_048.png
new file mode 100755
index 0000000000..5b9400dbdc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_si_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_zn_016.png b/examples/webkit/webkit-guide/img/ic_zn_016.png
new file mode 100755
index 0000000000..11e5705130
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_zn_016.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_zn_032.png b/examples/webkit/webkit-guide/img/ic_zn_032.png
new file mode 100755
index 0000000000..cb78a5c139
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_zn_032.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_zn_036.png b/examples/webkit/webkit-guide/img/ic_zn_036.png
new file mode 100755
index 0000000000..66abffd40d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_zn_036.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/ic_zn_048.png b/examples/webkit/webkit-guide/img/ic_zn_048.png
new file mode 100755
index 0000000000..d8361ad6c0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/ic_zn_048.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_check.png b/examples/webkit/webkit-guide/img/icon_check.png
new file mode 100755
index 0000000000..294b62d24d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_check.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_check_x24green.png b/examples/webkit/webkit-guide/img/icon_check_x24green.png
new file mode 100755
index 0000000000..803928c231
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_check_x24green.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_dismiss.png b/examples/webkit/webkit-guide/img/icon_dismiss.png
new file mode 100755
index 0000000000..e7a842640a
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_dismiss.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_dismiss_x22.png b/examples/webkit/webkit-guide/img/icon_dismiss_x22.png
new file mode 100755
index 0000000000..e52a62a598
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_dismiss_x22.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_drill-down.png b/examples/webkit/webkit-guide/img/icon_drill-down.png
new file mode 100755
index 0000000000..7928c6e59e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_drill-down.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_drill-down_x32.png b/examples/webkit/webkit-guide/img/icon_drill-down_x32.png
new file mode 100755
index 0000000000..477d7cda0d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_drill-down_x32.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_drill-up.png b/examples/webkit/webkit-guide/img/icon_drill-up.png
new file mode 100755
index 0000000000..ff7594054d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_drill-up.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_drill-up_x32.png b/examples/webkit/webkit-guide/img/icon_drill-up_x32.png
new file mode 100755
index 0000000000..d63fe083a1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_drill-up_x32.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_expand-nav.png b/examples/webkit/webkit-guide/img/icon_expand-nav.png
new file mode 100755
index 0000000000..7ec5aa68d1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_expand-nav.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_head-collapsed.png b/examples/webkit/webkit-guide/img/icon_head-collapsed.png
new file mode 100755
index 0000000000..ed47838b5b
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_head-collapsed.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_head-collapsed_x13.png b/examples/webkit/webkit-guide/img/icon_head-collapsed_x13.png
new file mode 100755
index 0000000000..6892dc08a6
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_head-collapsed_x13.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_head-expanded.png b/examples/webkit/webkit-guide/img/icon_head-expanded.png
new file mode 100755
index 0000000000..ee7e0a767a
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_head-expanded.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_head-expanded_x13.png b/examples/webkit/webkit-guide/img/icon_head-expanded_x13.png
new file mode 100755
index 0000000000..40e8eeb4c1
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_head-expanded_x13.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_info.png b/examples/webkit/webkit-guide/img/icon_info.png
new file mode 100755
index 0000000000..b70c760621
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_info.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_info_x24.png b/examples/webkit/webkit-guide/img/icon_info_x24.png
new file mode 100755
index 0000000000..9f4f352c84
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_info_x24.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-doc.png b/examples/webkit/webkit-guide/img/icon_link-doc.png
new file mode 100755
index 0000000000..fc9bd54e06
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-doc.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-email.png b/examples/webkit/webkit-guide/img/icon_link-email.png
new file mode 100755
index 0000000000..ef5f95d318
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-email.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-external.png b/examples/webkit/webkit-guide/img/icon_link-external.png
new file mode 100755
index 0000000000..47ddd807e4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-external.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-pdf.png b/examples/webkit/webkit-guide/img/icon_link-pdf.png
new file mode 100755
index 0000000000..fb90a6a2b9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-pdf.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-ppt.png b/examples/webkit/webkit-guide/img/icon_link-ppt.png
new file mode 100755
index 0000000000..c6a532878c
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-ppt.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-rss.png b/examples/webkit/webkit-guide/img/icon_link-rss.png
new file mode 100755
index 0000000000..d3cf2c4916
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-rss.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-sms.png b/examples/webkit/webkit-guide/img/icon_link-sms.png
new file mode 100755
index 0000000000..f36de100f8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-sms.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-tel.png b/examples/webkit/webkit-guide/img/icon_link-tel.png
new file mode 100755
index 0000000000..7b665ee5de
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-tel.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_link-xls.png b/examples/webkit/webkit-guide/img/icon_link-xls.png
new file mode 100755
index 0000000000..977c868eae
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_link-xls.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_list-all.png b/examples/webkit/webkit-guide/img/icon_list-all.png
new file mode 100755
index 0000000000..97ce879fb8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_list-all.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_list-all_circ.png b/examples/webkit/webkit-guide/img/icon_list-all_circ.png
new file mode 100755
index 0000000000..6c5828e835
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_list-all_circ.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_nav-start.png b/examples/webkit/webkit-guide/img/icon_nav-start.png
new file mode 100755
index 0000000000..cbe127fdc9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_nav-start.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_nav-top.png b/examples/webkit/webkit-guide/img/icon_nav-top.png
new file mode 100755
index 0000000000..d57d3efa11
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_nav-top.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_nav-up.png b/examples/webkit/webkit-guide/img/icon_nav-up.png
new file mode 100755
index 0000000000..bab32593e3
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_nav-up.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_nav_end.png b/examples/webkit/webkit-guide/img/icon_nav_end.png
new file mode 100755
index 0000000000..6d7dd319b4
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_nav_end.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_question.png b/examples/webkit/webkit-guide/img/icon_question.png
new file mode 100755
index 0000000000..28c2ae1f12
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_question.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_scroll-left.png b/examples/webkit/webkit-guide/img/icon_scroll-left.png
new file mode 100755
index 0000000000..38b3c3fa0e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_scroll-left.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_scroll-right.png b/examples/webkit/webkit-guide/img/icon_scroll-right.png
new file mode 100755
index 0000000000..4d6191942b
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_scroll-right.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/icon_trash.png b/examples/webkit/webkit-guide/img/icon_trash.png
new file mode 100755
index 0000000000..b5f6eaae73
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/icon_trash.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land1.jpg b/examples/webkit/webkit-guide/img/land1.jpg
new file mode 100644
index 0000000000..05b11d5393
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land1.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land2.jpg b/examples/webkit/webkit-guide/img/land2.jpg
new file mode 100644
index 0000000000..0f504b4106
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land2.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land3.jpg b/examples/webkit/webkit-guide/img/land3.jpg
new file mode 100644
index 0000000000..fd86c950e8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land3.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land4.jpg b/examples/webkit/webkit-guide/img/land4.jpg
new file mode 100644
index 0000000000..bcf33daf7f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land4.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land5.jpg b/examples/webkit/webkit-guide/img/land5.jpg
new file mode 100644
index 0000000000..c8d550923d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land5.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land6.jpg b/examples/webkit/webkit-guide/img/land6.jpg
new file mode 100644
index 0000000000..2762864634
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land6.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land7.jpg b/examples/webkit/webkit-guide/img/land7.jpg
new file mode 100644
index 0000000000..6ac6d88966
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land7.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/land8.jpg b/examples/webkit/webkit-guide/img/land8.jpg
new file mode 100644
index 0000000000..37c51df15e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/land8.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/mask.png b/examples/webkit/webkit-guide/img/mask.png
new file mode 100755
index 0000000000..f9764b54aa
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/mask.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal1.jpg b/examples/webkit/webkit-guide/img/tmp/gal1.jpg
new file mode 100644
index 0000000000..8f9edcb2ca
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal1.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal2.jpg b/examples/webkit/webkit-guide/img/tmp/gal2.jpg
new file mode 100644
index 0000000000..a2301ef22f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal2.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal3.jpg b/examples/webkit/webkit-guide/img/tmp/gal3.jpg
new file mode 100644
index 0000000000..a768530a8c
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal3.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal4.jpg b/examples/webkit/webkit-guide/img/tmp/gal4.jpg
new file mode 100644
index 0000000000..96c00015c0
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal4.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal5.jpg b/examples/webkit/webkit-guide/img/tmp/gal5.jpg
new file mode 100644
index 0000000000..6ec78fc43a
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal5.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal6.jpg b/examples/webkit/webkit-guide/img/tmp/gal6.jpg
new file mode 100644
index 0000000000..25eb95cb22
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal6.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal7.jpg b/examples/webkit/webkit-guide/img/tmp/gal7.jpg
new file mode 100644
index 0000000000..b9fda2fb9d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal7.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/gal8.jpg b/examples/webkit/webkit-guide/img/tmp/gal8.jpg
new file mode 100644
index 0000000000..c23e2260c3
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/gal8.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land1.jpg b/examples/webkit/webkit-guide/img/tmp/land1.jpg
new file mode 100644
index 0000000000..05b11d5393
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land1.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land2.jpg b/examples/webkit/webkit-guide/img/tmp/land2.jpg
new file mode 100644
index 0000000000..0f504b4106
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land2.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land3.jpg b/examples/webkit/webkit-guide/img/tmp/land3.jpg
new file mode 100644
index 0000000000..fd86c950e8
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land3.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land4.jpg b/examples/webkit/webkit-guide/img/tmp/land4.jpg
new file mode 100644
index 0000000000..bcf33daf7f
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land4.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land5.jpg b/examples/webkit/webkit-guide/img/tmp/land5.jpg
new file mode 100644
index 0000000000..c8d550923d
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land5.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land6.jpg b/examples/webkit/webkit-guide/img/tmp/land6.jpg
new file mode 100644
index 0000000000..2762864634
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land6.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land7.jpg b/examples/webkit/webkit-guide/img/tmp/land7.jpg
new file mode 100644
index 0000000000..6ac6d88966
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land7.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tmp/land8.jpg b/examples/webkit/webkit-guide/img/tmp/land8.jpg
new file mode 100644
index 0000000000..37c51df15e
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tmp/land8.jpg
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal1.png b/examples/webkit/webkit-guide/img/tnail_gal1.png
new file mode 100644
index 0000000000..6c83482e25
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal1.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal2.png b/examples/webkit/webkit-guide/img/tnail_gal2.png
new file mode 100644
index 0000000000..f090b68959
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal2.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal3.png b/examples/webkit/webkit-guide/img/tnail_gal3.png
new file mode 100644
index 0000000000..6cc257b490
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal3.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal4.png b/examples/webkit/webkit-guide/img/tnail_gal4.png
new file mode 100644
index 0000000000..ae9983ccbc
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal4.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal5.png b/examples/webkit/webkit-guide/img/tnail_gal5.png
new file mode 100644
index 0000000000..58d764c9a9
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal5.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal6.png b/examples/webkit/webkit-guide/img/tnail_gal6.png
new file mode 100644
index 0000000000..f5d0b8b657
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal6.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal7.png b/examples/webkit/webkit-guide/img/tnail_gal7.png
new file mode 100644
index 0000000000..8d33ea69f6
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal7.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/img/tnail_gal8.png b/examples/webkit/webkit-guide/img/tnail_gal8.png
new file mode 100644
index 0000000000..61e1431ab5
--- /dev/null
+++ b/examples/webkit/webkit-guide/img/tnail_gal8.png
Binary files differ
diff --git a/examples/webkit/webkit-guide/js/anim_accord.js b/examples/webkit/webkit-guide/js/anim_accord.js
new file mode 100755
index 0000000000..8d58a18c7e
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/anim_accord.js
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+
+ initDT();
+ document.querySelector('body').addEventListener('click', function(event){
+ var dl = document.querySelector('#accordion');
+ var ct = event.currentTarget;
+ var t = event.target;
+ var dt;
+ if (t.id == 'accordion' && t.className == 'collapsed') {
+ dl.className = 'expanded';
+ }
+ else if (t.tagName == 'DT' && t.parentNode.id == 'accordion') {
+ if ( t.className == 'collapsed' ) {
+ t.className = 'expanded';
+ }
+ else {
+ t.className = 'collapsed';
+ }
+ }
+ else {
+ dl.className = 'collapsed';
+ initDT();
+ }
+ });
+};
+
+function initDT() {
+ var el = nlToAr(document.querySelectorAll('#accordion > dt'));
+ el.forEach( function(l){ l.className = 'collapsed'; });
+}
+
+function nlToAr(nl) {
+ var a = new Array();
+ var l = nl.length;
+ var i = l - 1;
+ a[i] = true;
+ for ( i = 0; i < l ; i++ ) { a[i] = nl[i]; }
+ return(a);
+}
diff --git a/examples/webkit/webkit-guide/js/anim_gallery.js b/examples/webkit/webkit-guide/js/anim_gallery.js
new file mode 100755
index 0000000000..3e00bc6f30
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/anim_gallery.js
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+var app = new Function();
+
+app.init = function() {
+ var divs = document.querySelectorAll('section > div');
+ if ( divs.length < 2 ) return false;
+ for (var i = 0, l = divs.length ; i < l ; i++ ) {
+ if (i > 1) divs[i].className = 'hideR';
+ divs[i].addEventListener('click', app.navigate );
+ }
+ divs[0].className = 'selected';
+ divs[1].className = 'queueR';
+};
+
+app.navigate = function(event) {
+ var el, n1, n2, p1, p2;
+ el = event.currentTarget;
+ n1 = el.nextSibling;
+ if (n1) n2 = el.nextSibling.nextSibling;
+ p1 = el.previousSibling;
+ if (p1) p2 = el.previousSibling.previousSibling;
+ if ( el.className == 'selected' ) {
+ if ( el.id == 'reveal') {
+ el.id = '';
+ }
+ else {
+ el.id = 'reveal';
+ }
+ return false;
+ }
+ if (n1) { n1.className = 'queueR'; n1.id = ''}
+ if (n2) { n2.className = 'hideR'; n2.id = '' }
+ if (p1) { p1.className = 'queueL'; p1.id = '' }
+ if (p2) { p2.className = 'hideL'; p2.id = '' }
+ el.className = 'selected';
+};
+
+window.onload = function() {
+ // alert(app.init);
+ app.init();
+};
diff --git a/examples/webkit/webkit-guide/js/anim_panel.js b/examples/webkit/webkit-guide/js/anim_panel.js
new file mode 100755
index 0000000000..365210d84a
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/anim_panel.js
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ document.querySelector('body').addEventListener('click', function(event){
+ document.querySelector('#panel').className = 'collapsed';
+ });
+}
+
+function share() {
+ document.querySelector('#panel').className = 'expanded';
+ event.stopPropagation();
+}
+
+function debug(str) {
+ document.querySelector('#dbg').innerHTML = 'You chose the <b>' + str.toUpperCase() + '</b> option.';
+}
diff --git a/examples/webkit/webkit-guide/js/anim_skew.js b/examples/webkit/webkit-guide/js/anim_skew.js
new file mode 100755
index 0000000000..1a80a6d7a8
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/anim_skew.js
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+var app = new Function();
+
+app.init = function() {
+ app.elements = document.querySelectorAll('.items > div');
+ app.navs = document.querySelectorAll('nav > div');
+
+ // elements
+ for ( var i = 0, ln = app.elements.length ; i < ln ; i++ ) {
+ app.elements[i].className = 'row' + (i + 1);
+ app.elements[i].addEventListener('click', app.remove);
+ }
+
+ // navigation
+ for ( var i = 0, ln = app.navs.length ; i < ln ; i++ ) {
+ app.navs[i].addEventListener('click', app.filter );
+ }
+};
+
+app.filter = function(event) {
+ var type = event.target.className;
+
+ var hiddenCount = 0;
+
+ if (! type ) {
+ app.init();
+ return false;
+ }
+
+ for ( var i = 0, ln = app.elements.length ; i < ln ; i++ ) {
+ if ( app.elements[i].title == type ) {
+ app.elements[i].className = 'row' + ((i + 1) - hiddenCount);
+ }
+ else {
+ app.elements[i].className = 'hide';
+ hiddenCount++;
+ }
+ }
+};
+
+app.remove = function() {
+ event.currentTarget.className = 'hide';
+ app.rearrange();
+};
+
+app.rearrange = function() {
+ var hiddenCount = 0;
+ for ( var i = 0, ln = app.elements.length ; i < ln ; i++ ) {
+ if ( app.elements[i].className.match(/hide/) ) {
+ hiddenCount++;
+ }
+ else {
+ app.elements[i].className = 'row' + ((i + 1) - hiddenCount);
+ }
+ }
+};
+
+window.onload = function() { app.init() };
+
diff --git a/examples/webkit/webkit-guide/js/css3_backgrounds.js b/examples/webkit/webkit-guide/js/css3_backgrounds.js
new file mode 100755
index 0000000000..0c834d1dc8
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_backgrounds.js
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+document.querySelector('body').addEventListener('click', function(event) {
+ var l = event.target;
+ if (l.tagName != 'DT') return false ;
+ if ( l.className ) {
+ l.className = '';
+ }
+ else {
+ l.className = 'selected';
+ }
+});
diff --git a/examples/webkit/webkit-guide/js/css3_border-img.js b/examples/webkit/webkit-guide/js/css3_border-img.js
new file mode 100755
index 0000000000..b440afbfb5
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_border-img.js
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ var el = document.querySelectorAll('input');
+ for (var i = 0, l = el.length ; i < l ; i++ ) {
+ }
+}
diff --git a/examples/webkit/webkit-guide/js/css3_grad-radial.js b/examples/webkit/webkit-guide/js/css3_grad-radial.js
new file mode 100755
index 0000000000..46601e4d69
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_grad-radial.js
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ var el = document.querySelector('#main');
+ el.addEventListener('mousedown', function(event){
+
+ var colors = [ 'beige', 'crimson', 'darkcyan', 'turquoise',
+ 'darkgoldenrod', 'darkorange', 'fuchsia',
+ 'greenyellow', 'lightblue', 'lightcoral',
+ 'lightgreen', 'mediumorchid', 'pink', 'plum',
+ 'skyblue', 'springgreen', 'tan', 'tomato',
+ 'violet', 'yellow', 'teal'];
+
+ var x = event.offsetX;
+ var y = event.offsetY;
+
+ var loc = document.querySelector('#localStyles');
+ var style = '#main:active {' + 'background: -webkit-gradient(radial, ';
+ style += (x + ' ');
+ style += (y + ' ');
+ style += ',5,';
+ style += ((x + 10) + ' ');
+ style += ((y + 10) + ' ');
+ style += ', 48, ';
+ style += 'from(' + colors[r(5)] + '),';
+ style += 'color-stop(20%, ' + colors[r(5)] + '),';
+ style += 'color-stop(40%, ' + colors[r(5)] + '),';
+ style += 'color-stop(60%, ' + colors[r(5)] + '),';
+ style += 'color-stop(80%, ' + colors[r(5)] + '),';
+ style += 'to(#ffffff) );'
+ style += '}'
+ loc.innerHTML = style;
+ });
+}
+
+function r(i) {
+ return Math.floor( (Math.random() * i ) );
+}
diff --git a/examples/webkit/webkit-guide/js/css3_mask-grad.js b/examples/webkit/webkit-guide/js/css3_mask-grad.js
new file mode 100755
index 0000000000..5d516aa93c
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_mask-grad.js
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+document.querySelector('body').addEventListener('click', function(event) {
+ var l = event.target;
+ if (l.tagName != 'IMG') return false ;
+ event.target.className = 'select';
+});
diff --git a/examples/webkit/webkit-guide/js/css3_mask-img.js b/examples/webkit/webkit-guide/js/css3_mask-img.js
new file mode 100755
index 0000000000..b440afbfb5
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_mask-img.js
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ var el = document.querySelectorAll('input');
+ for (var i = 0, l = el.length ; i < l ; i++ ) {
+ }
+}
diff --git a/examples/webkit/webkit-guide/js/css3_text-overflow.js b/examples/webkit/webkit-guide/js/css3_text-overflow.js
new file mode 100755
index 0000000000..1a87cb3c83
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/css3_text-overflow.js
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ var el = document.querySelectorAll('.accordion > li');
+ for (var i = 0, l = el.length ; i < l ; i++ ) {
+ el[i].addEventListener('click', function(event){
+ var tgt = event.target;
+ if ( tgt.tagName == 'LI' && ( ! tgt.className ) ) {
+ tgt.className = 'selected';
+ }
+ if ( tgt.tagName == 'DIV' && ( tgt.className == 'dismiss') ) {
+ tgt.parentNode.className = '';
+ }
+
+ });
+ }
+}
diff --git a/examples/webkit/webkit-guide/js/form_tapper.js b/examples/webkit/webkit-guide/js/form_tapper.js
new file mode 100755
index 0000000000..bb0c9dca19
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/form_tapper.js
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ return false;
+ var el = document.querySelectorAll('input[type=radio]');
+ for ( var i = 0, l = el.length ; i < l ; i++ ) {
+ el[i].addEventListener('click', resetRadio);
+ }
+}
+
+function resetRadio(event) {
+ if (event.target._checked == true) {
+ event.target._checked = false;
+ event.target.checked = false;
+ event.target.indeterminate = true;
+ }
+ else {
+ event.target._checked = true;
+ }
+}
diff --git a/examples/webkit/webkit-guide/js/mob_condjs.js b/examples/webkit/webkit-guide/js/mob_condjs.js
new file mode 100755
index 0000000000..1ba445e4b2
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/mob_condjs.js
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+window.onload = function() {
+ var msg = 'JavaScript thinks you are viewing this page with a ';
+ if ( isDesign('desktop') ) {
+ msg += 'full desktop browser';
+ }
+ else if ( isDesign('touch') ) {
+ msg += 'touch-based mobile browser';
+ }
+ else if ( isDesign('mobile') ) {
+ msg += 'non-touch mobile browser';
+ }
+ else {
+ msg = window.styleMedia.matchMedium;
+ }
+ document.getElementById('js').innerHTML = msg;
+};
+
+function isDesign(str) {
+ var design;
+ if (matchesMedia('only screen and (min-device-width: 481px)')) {
+ design = 'desktop';
+ }
+ else if (matchesMedia('only screen and (max-device-width: 480px)')) {
+ design = 'touch';
+ }
+ else if (matchesMedia('handheld')) {
+ design = 'mobile';
+ }
+ return str == design;
+}
+
+function matchesMedia(query) {
+ if (!!window.matchMedia)
+ return window.matchMedia(query).matches;
+ if (!!window.styleMedia && !!window.styleMedia.matchMedium)
+ return window.styleMedia.matchMedium(query);
+ if (!!window.media && window.media.matchMedium)
+ return window.media.matchMedium(query);
+ return false;
+}
diff --git a/examples/webkit/webkit-guide/js/mobile.js b/examples/webkit/webkit-guide/js/mobile.js
new file mode 100755
index 0000000000..880d6e45bc
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/mobile.js
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+var app = new Function();
+
+app.toggleDisplay = function(id) {
+ var el = document.getElementById(id);
+ if (el.className.match(/hidden/)) {
+ el.className = '';
+ }
+ else {
+ el.className = 'hidden';
+ }
+}
diff --git a/examples/webkit/webkit-guide/js/storage.js b/examples/webkit/webkit-guide/js/storage.js
new file mode 100755
index 0000000000..62dca84808
--- /dev/null
+++ b/examples/webkit/webkit-guide/js/storage.js
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt WebKit 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$
+**
+****************************************************************************/
+var app = new Function();
+
+app.dbg = false;
+
+window.onload = function() {
+
+ app.cred = document.querySelector('#cred');
+
+ // open form:
+ document.querySelector('#openform').addEventListener('mousedown', app.getInfo);
+ // dismiss form:
+ document.querySelector('#dismiss').addEventListener('mousedown', app.dismiss);
+
+ // form validation:
+ app.inputs = document.querySelectorAll('input:not([type="submit"])');
+ for (var i = 0, l = app.inputs.length ; i < l ; i++ ) {
+ app.inputs[i].addEventListener('blur', app.checkEdit);
+ }
+
+ // storage
+ app.db_loc = window.localStorage;
+ app.db_ses = window.sessionStorage;
+
+ if (!!app.db_loc) {
+ // no login info yet...
+ if ( !app.db_loc.getItem('login') || !app.db_loc.getItem('password') ) app.getInfo();
+ }
+ else {
+ alert("This application needs to run on a recent WebKit-based browser.");
+ }
+
+};
+
+app.hint = function(str) {
+ document.querySelector('body').className = str;
+};
+
+app.checkEdit = function(ev) {
+ ev.currentTarget.className = 'validate';
+}
+
+app.getInfo = function(ev) {
+ app.cred.className = 'show';
+ app.inputs[0].value = app.db_loc.getItem('login');
+ app.inputs[1].value = app.db_loc.getItem('password');
+ app.inputs[2].value = app.db_ses.getItem('credit');
+}
+
+app.dismiss = function(ev) {
+ app.db_loc.setItem('login', app.inputs[0].value);
+ app.db_loc.setItem('password', app.inputs[1].value);
+ app.db_ses.setItem('credit', app.inputs[2].value);
+ ev.currentTarget.parentNode.className = 'hide';
+}
+
diff --git a/examples/webkit/webkit-guide/layout_link-fmt.htm b/examples/webkit/webkit-guide/layout_link-fmt.htm
new file mode 100644
index 0000000000..436d97c1f9
--- /dev/null
+++ b/examples/webkit/webkit-guide/layout_link-fmt.htm
@@ -0,0 +1,81 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Link Context Hints</title>
+<link href='css/layout_link-fmt.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<article>
+<h3>Link Context Hints</h3>
+<ol class="links">
+<li> <a href="#">Link to internal page</a></li>
+<li> <a href="http://www.google.com" target="new">Link to external page</a></li>
+<li> <a href="mailto:who@where.com">Email Link</a></li>
+<li> <a href="tel:+2125551212">Phone: 212.555.1212</a></li>
+<li> <a href="sms:+2125551212%3Fbody=hello world">SMS Link</a></li>
+<li> <a href="http://whmp.com/pages/podcast/122411.rss">Link to RSS feed</a></li>
+<li> <a href="http://www.ous.edu/about/polipro/files/Budget%20Outline.doc">Link to Word file</a></li>
+<li> <a href="http://www.greenfield-nh.gov/Public_Documents/GreenfieldNH_Admin/BudgetReport2006.pdf">List to PDF file</a></li>
+<li> <a href="http://www.agmconnect.org/cpf/CPF_Budget_Template.xls">Link to Excel file</a></li>
+<li> <a href="http://www.unh.edu/hr/banner/position-budget-training.ppt">Link to Powerpoint file</a></li>
+</ol>
+<h3>Inline Links</h3>
+<p>
+Links to an
+<a href="item2.htm">internal page</a>, an
+<a href="http://example.com/item1.htm" target="new">external page</a>,
+<a href="mailto:who@where.com">email link</a>,
+phone link
+<a href="tel:+2125551212">212.555.1212</a>,
+<a href="sms:+2125551212%3Fbody=hello world">SMS Link</a>,
+<a href="http://whmp.com/pages/podcast/122411.rss">RSS feed</a>,
+<a href="http://www.ous.edu/about/polipro/files/Budget%20Outline.doc">Word file</a>,
+<a href="http://www.greenfield-nh.gov/Public_Documents/GreenfieldNH_Admin/BudgetReport2006.pdf">PDF</a>,
+<a href="http://www.agmconnect.org/cpf/CPF_Budget_Template.xls">Excel</a>,
+<a href="http://www.unh.edu/hr/banner/position-budget-training.ppt">Powerpoint</a>.
+</p>
+</article>
+<p>&nbsp</p>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/layout_tbl-keyhole.htm b/examples/webkit/webkit-guide/layout_tbl-keyhole.htm
new file mode 100644
index 0000000000..73d332d0c6
--- /dev/null
+++ b/examples/webkit/webkit-guide/layout_tbl-keyhole.htm
@@ -0,0 +1,141 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Mobilized Tables</title>
+<link href='css/layout_tbl-keyhole.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+
+<article id="r0">
+
+<h1>Mobilized Tables</h1>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
+feugiat gravida viverra. Vivamus ipsum felis, cursus sed venenatis
+nec, tempus ac tellus.</p>
+
+<p><a href="#r1">View Listings</a></p>
+
+<table class="mobile">
+
+<thead>
+<tr>
+<th class="nav"></th>
+<th>Item</th>
+<th>Price</th>
+<th>Location</th>
+<th>Posted</th>
+<th>Description</th>
+</tr>
+</thead>
+
+<tbody>
+
+<tr id="r1">
+<th class="nav"><a href="#"></a><a href="#r2"></a></th>
+<td>Keiser Indoor Cycling Bike / Platform</td>
+<td>$250</td>
+<td>Santa Monica, CA</td>
+<td>4 days ago</td>
+<td>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
+officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit
+amet, consectetur adipiscing elit. Donec feugiat gravida viverra.
+Vivamus ipsum felis, cursus sed venenatis nec, tempus ac tellus.</td>
+</tr>
+
+<tr id="r2">
+<th class="nav"><a href="#r1"></a><a href="#r3"></a></th>
+<td>Ladies Diamondback Mountain Bike</td>
+<td>$300</td>
+<td>North Hollywood, CA</td>
+<td>3 hours ago</td>
+<td>Duis aute irure dolor in reprehenderit in voluptate velit esse
+cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet,
+consectetur adipiscing elit. Donec feugiat gravida viverra. Vivamus
+ipsum felis, cursus sed venenatis nec, tempus ac tellus.</td>
+</tr>
+
+<tr id="r3">
+<th class="nav"><a href="#r2"></a><a href="#r4"></a></th>
+<td>AA Cycle 10 Speed Road Bike</td>
+<td>$150</td>
+<td>Burbank, CA</td>
+<td>2 days ago</td>
+<td>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet,
+consectetur adipiscing elit. Donec feugiat gravida viverra. Vivamus
+ipsum felis, cursus sed venenatis nec, tempus ac tellus.</td>
+</tr>
+
+<tr id="r4">
+<th class="nav"><a href="#r3"></a><a href="#"></a></th>
+<td>Magna Dual Suspection Mountain Bike 24</td>
+<td>$60</td>
+<td>El Segundo, CA</td>
+<td>2 weeks ago</td>
+<td>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem
+ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat
+gravida viverra. Vivamus ipsum felis, cursus sed venenatis nec, tempus
+ac tellus.</td>
+</tr>
+
+</tbody>
+
+</table>
+
+<p>
+Text continues here. Donec a massa felis, a congue purus. Nullam et
+turpis diam. Aenean vestibulum egestas metus, eu sodales dolor
+venenatis quis. Aenean augue orci, facilisis et convallis ut, egestas
+at neque.
+</p>
+</article>
+
+<script src="js/mobile.js"></script>
+
+</section>
+
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/mob_condjs.htm b/examples/webkit/webkit-guide/mob_condjs.htm
new file mode 100644
index 0000000000..710a3710fb
--- /dev/null
+++ b/examples/webkit/webkit-guide/mob_condjs.htm
@@ -0,0 +1,65 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Media Queries + JavaScript</title>
+<link media='only screen and (min-device-width: 481px)' href='css/mq_desktop.css' type='text/css' rel='stylesheet'/>
+<link media='only screen and (max-device-width: 480px)' href='css/mq_touch.css' type='text/css' rel='stylesheet'/>
+<link media='handheld' href='css/mqmobile.css' type='text/css' rel='stylesheet'/>
+<link href='css/mob_condjs.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>Media Queries + JavaScript</h3>
+<p id="design">...</p>
+
+<p id="js">...</p>
+
+</article>
+</section>
+
+<script src="js/mob_condjs.js"></script>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/mob_layout.htm b/examples/webkit/webkit-guide/mob_layout.htm
new file mode 100644
index 0000000000..cad6f6c635
--- /dev/null
+++ b/examples/webkit/webkit-guide/mob_layout.htm
@@ -0,0 +1,59 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). All
+rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<title>Media Query-Driven Layout</title>
+<meta name='viewport' content='width=device-width' />
+<title>media-driven layout</title>
+<link media='only screen and (min-device-width: 480px)' href='css/mqlayout_desktop.css' type='text/css' rel='stylesheet'/>
+<link media='only screen and (max-device-width: 480px)' href='css/mqlayout_touch.css' type='text/css' rel='stylesheet'/>
+<link media='handheld' href='css/mqlayout_mobile.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<header>HEADER</header>
+<nav>NAVIGATION</nav>
+<section id="main">MAIN CONTENT</section>
+<section id="sidebar">SIDEBAR</section>
+<footer>FOOTER</footer>
+
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/mob_mediaquery.htm b/examples/webkit/webkit-guide/mob_mediaquery.htm
new file mode 100644
index 0000000000..3b0e3b4e9c
--- /dev/null
+++ b/examples/webkit/webkit-guide/mob_mediaquery.htm
@@ -0,0 +1,59 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Media Queries</title>
+<link media='only screen and (min-device-width: 481px)' href='css/mq_desktop.css' type='text/css' rel='stylesheet'/>
+<link media='only screen and (max-device-width: 480px)' href='css/mq_touch.css' type='text/css' rel='stylesheet'/>
+<link media='handheld' href='css/mq_mobile.css' type='text/css' rel='stylesheet'/>
+<link href='css/mob_mediaquery.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<section>
+<article>
+<h3>Media Queries</h3>
+<p id="design">...</p>
+</article>
+</section>
+<script src="js/mobile.js"></script>
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/storage.htm b/examples/webkit/webkit-guide/storage.htm
new file mode 100644
index 0000000000..d154c81567
--- /dev/null
+++ b/examples/webkit/webkit-guide/storage.htm
@@ -0,0 +1,71 @@
+<!--
+
+This file is part of QtWebKit
+
+Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+All rights reserved.
+
+You may use this file under the terms of the BSD license as follows:
+
+"Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+o Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+o Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+o Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+ the names of its contributors may be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+
+-->
+
+<!DOCTYPE html>
+<html>
+<head>
+<meta name='viewport' content='width=device-width' />
+<title>Local/Session Storage</title>
+<link href='css/storage.css' type='text/css' rel='stylesheet'/>
+</head>
+<body>
+<h1>
+<img id="openform" src="img/icon_info_x24.png"/>
+Local/Session Storage</h1>
+
+<form id="cred" class="hide">
+
+<img id="dismiss" src="img/icon_dismiss.png"/>
+
+<div>login</div>
+<input id="login" required type="text"/>
+<br/>
+
+<div>password</div>
+<input id="password" required type="password"/>
+
+<div>credit card</div>
+<input id="credit" required type="number" min="999999999999999" max="9999999999999999"/>
+
+</form>
+
+<script src="js/storage.js"></script>
+
+</body>
+</html>
diff --git a/examples/webkit/webkit-guide/webkit-guide.pro b/examples/webkit/webkit-guide/webkit-guide.pro
new file mode 100644
index 0000000000..b4291a5e01
--- /dev/null
+++ b/examples/webkit/webkit-guide/webkit-guide.pro
@@ -0,0 +1,257 @@
+#A simple .pro file to make Qt aware of the webkit-guide files.
+#For documentation generation
+#TEMPLATE += subdirs
+
+SOURCES = anim_accord.htm \
+anim_demo-rotate.htm \
+anim_demo-scale.htm \
+anim_demo-skew.htm \
+anim_gallery.htm \
+anim_panel.htm \
+anim_pulse.htm \
+anim_skew.htm \
+anim_slide1.htm \
+anim_slide2.htm \
+anim_slide3.htm \
+anim_tabbedSkew.htm \
+_copyright.txt \
+css3_backgrounds.htm \
+css3_border-img.htm \
+css3_gradientBack.htm \
+css3_gradientBackStop.htm \
+css3_gradientButton.htm \
+css3_grad-radial.htm \
+css3_mask-grad.htm \
+css3_mask-img.htm \
+css3_multicol.htm \
+css3_reflect.htm \
+css3_scroll.htm \
+css3_sel-nth.htm \
+css3_shadow.htm \
+css3_text-overflow.htm \
+css3_text-shadow.htm \
+css3_text-stroke.htm \
+form_tapper.htm \
+form_toggler.htm \
+_image_assets.htm \
+_index.html \
+layout_link-fmt.htm \
+layout_tbl-keyhole.htm \
+mob_condjs.htm \
+mob_layout.htm \
+mob_mediaquery.htm \
+storage.htm \
+css/anim_accord.css \
+css/anim_demo-rotate.css \
+css/anim_demo-scale.css \
+css/anim_demo-skew.css \
+css/anim_gallery.css \
+css/anim_panel.css \
+css/anim_pulse.css \
+css/anim_skew.css \
+css/anim_slide.css \
+css/anim_tabbedSkew.css \
+css/css3_backgrounds.css \
+css/css3_border-img.css \
+css/css3_gradientBack.css \
+css/css3_gradientBackStop.css \
+css/css3_gradientButton.css \
+css/css3_grad-radial.css \
+css/css3_mask-grad.css \
+css/css3_mask-img.css \
+css/css3_multicol.css \
+css/css3_reflect.css \
+css/css3_scroll.css \
+css/css3_sel-nth.css \
+css/css3_shadowBlur.css \
+css/css3_shadow.css \
+css/css3_text-overflow.css \
+css/css3_text-shadow.css \
+css/css3_text-stroke.css \
+css/form_tapper.css \
+css/form_toggler.css \
+css/layout_link-fmt.css \
+css/layout_tbl-keyhole.css \
+css/mob_condjs.css \
+css/mobile.css \
+css/mob_mediaquery.css \
+css/mq_desktop.css \
+css/mqlayout_desktop.css \
+css/mqlayout_mobile.css \
+css/mqlayout_touch.css \
+css/mq_mobile.css \
+css/mq_touch.css \
+css/storage.css \
+img/border-frame.png \
+img/gal1.jpg \
+img/gal2.jpg \
+img/gal3.jpg \
+img/gal4.jpg \
+img/gal5.jpg \
+img/gal6.jpg \
+img/gal7.jpg \
+img/gal8.jpg \
+img/gradient.jpg \
+img/gray_icon_close.png \
+img/ic_ag_016.png \
+img/ic_ag_032.png \
+img/ic_ag_036.png \
+img/ic_ag_048.png \
+img/ic_al_016.png \
+img/ic_al_032.png \
+img/ic_al_036.png \
+img/ic_al_048.png \
+img/ic_ar_016.png \
+img/ic_ar_032.png \
+img/ic_ar_036.png \
+img/ic_ar_048.png \
+img/ic_b_016.png \
+img/ic_b_032.png \
+img/ic_b_036.png \
+img/ic_b_048.png \
+img/ic_be_016.png \
+img/ic_be_032.png \
+img/ic_be_036.png \
+img/ic_be_048.png \
+img/ic_c_016.png \
+img/ic_c_032.png \
+img/ic_c_036.png \
+img/ic_c_048.png \
+img/ic_ca_016.png \
+img/ic_ca_032.png \
+img/ic_ca_036.png \
+img/ic_ca_048.png \
+img/ic_cl_016.png \
+img/ic_cl_032.png \
+img/ic_cl_036.png \
+img/ic_cl_048.png \
+img/ic_cu_016.png \
+img/ic_cu_032.png \
+img/ic_cu_036.png \
+img/ic_cu_048.png \
+img/ic_f_016.png \
+img/ic_f_032.png \
+img/ic_f_036.png \
+img/ic_f_048.png \
+img/ic_fe_016.png \
+img/ic_fe_032.png \
+img/ic_fe_036.png \
+img/ic_fe_048.png \
+img/ic_h_016.png \
+img/ic_h_032.png \
+img/ic_h_036.png \
+img/ic_h_048.png \
+img/ic_he_016.png \
+img/ic_he_032.png \
+img/ic_he_036.png \
+img/ic_he_048.png \
+img/ic_k_016.png \
+img/ic_k_032.png \
+img/ic_k_036.png \
+img/ic_k_048.png \
+img/ic_li_016.png \
+img/ic_li_032.png \
+img/ic_li_036.png \
+img/ic_li_048.png \
+img/ic_mg_016.png \
+img/ic_mg_032.png \
+img/ic_mg_036.png \
+img/ic_mg_048.png \
+img/ic_n_016.png \
+img/ic_n_032.png \
+img/ic_n_036.png \
+img/ic_n_048.png \
+img/ic_na_016.png \
+img/ic_na_032.png \
+img/ic_na_036.png \
+img/ic_na_048.png \
+img/ic_ne_016.png \
+img/ic_ne_032.png \
+img/ic_ne_036.png \
+img/ic_ne_048.png \
+img/ic_ni_016.png \
+img/ic_ni_032.png \
+img/ic_ni_036.png \
+img/ic_ni_048.png \
+img/ic_o_016.png \
+img/ic_o_032.png \
+img/ic_o_036.png \
+img/ic_o_048.png \
+img/icon_check.png \
+img/icon_check_x24green.png \
+img/icon_dismiss.png \
+img/icon_dismiss_x22.png \
+img/icon_drill-down.png \
+img/icon_drill-down_x32.png \
+img/icon_drill-up.png \
+img/icon_drill-up_x32.png \
+img/icon_expand-nav.png \
+img/icon_head-collapsed.png \
+img/icon_head-collapsed_x13.png \
+img/icon_head-expanded.png \
+img/icon_head-expanded_x13.png \
+img/icon_info.png \
+img/icon_info_x24.png \
+img/icon_link-doc.png \
+img/icon_link-email.png \
+img/icon_link-external.png \
+img/icon_link-pdf.png \
+img/icon_link-ppt.png \
+img/icon_link-rss.png \
+img/icon_link-sms.png \
+img/icon_link-tel.png \
+img/icon_link-xls.png \
+img/icon_list-all_circ.png \
+img/icon_list-all.png \
+img/icon_nav_end.png \
+img/icon_nav-start.png \
+img/icon_nav-top.png \
+img/icon_nav-up.png \
+img/icon_question.png \
+img/icon_scroll-left.png \
+img/icon_scroll-right.png \
+img/icon_trash.png \
+img/ic_pt_016.png \
+img/ic_pt_032.png \
+img/ic_pt_036.png \
+img/ic_pt_048.png \
+img/ic_si_016.png \
+img/ic_si_032.png \
+img/ic_si_036.png \
+img/ic_si_048.png \
+img/ic_zn_016.png \
+img/ic_zn_032.png \
+img/ic_zn_036.png \
+img/ic_zn_048.png \
+img/land1.jpg \
+img/land2.jpg \
+img/land3.jpg \
+img/land4.jpg \
+img/land5.jpg \
+img/land6.jpg \
+img/land7.jpg \
+img/land8.jpg \
+img/mask.png \
+img/tnail_gal1.png \
+img/tnail_gal2.png \
+img/tnail_gal3.png \
+img/tnail_gal4.png \
+img/tnail_gal5.png \
+img/tnail_gal6.png \
+img/tnail_gal7.png \
+img/tnail_gal8.png \
+js/anim_accord.js \
+js/anim_gallery.js \
+js/anim_panel.js \
+js/anim_skew.js \
+js/css3_backgrounds.js \
+js/css3_border-img.js \
+js/css3_grad-radial.js \
+js/css3_mask-grad.js \
+js/css3_mask-img.js \
+js/css3_text-overflow.js \
+js/form_tapper.js \
+js/mob_condjs.js \
+js/mobile.js \
+js/storage.js \
+
diff --git a/examples/widgets/README b/examples/widgets/README
new file mode 100644
index 0000000000..fd16c67acd
--- /dev/null
+++ b/examples/widgets/README
@@ -0,0 +1,44 @@
+Qt comes with a large range of standard widgets that users of modern
+applications have come to expect.
+
+You can also develop your own custom widgets and controls, and use them
+alongside standard widgets.
+
+It is even possible to provide custom styles and themes for widgets that can
+be used to change the appearance of standard widgets and appropriately
+written custom widgets.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/widgets/analogclock/analogclock.cpp b/examples/widgets/analogclock/analogclock.cpp
new file mode 100644
index 0000000000..5368a2cbe1
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "analogclock.h"
+
+//! [0] //! [1]
+AnalogClock::AnalogClock(QWidget *parent)
+//! [0] //! [2]
+ : QWidget(parent)
+//! [2] //! [3]
+{
+//! [3] //! [4]
+ QTimer *timer = new QTimer(this);
+//! [4] //! [5]
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+//! [5] //! [6]
+ timer->start(1000);
+//! [6]
+
+ setWindowTitle(tr("Analog Clock"));
+ resize(200, 200);
+//! [7]
+}
+//! [1] //! [7]
+
+//! [8] //! [9]
+void AnalogClock::paintEvent(QPaintEvent *)
+//! [8] //! [10]
+{
+ static const QPoint hourHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -40)
+ };
+ static const QPoint minuteHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -70)
+ };
+
+ QColor hourColor(127, 0, 127);
+ QColor minuteColor(0, 127, 127, 191);
+
+ int side = qMin(width(), height());
+ QTime time = QTime::currentTime();
+//! [10]
+
+//! [11]
+ QPainter painter(this);
+//! [11] //! [12]
+ painter.setRenderHint(QPainter::Antialiasing);
+//! [12] //! [13]
+ painter.translate(width() / 2, height() / 2);
+//! [13] //! [14]
+ painter.scale(side / 200.0, side / 200.0);
+//! [9] //! [14]
+
+//! [15]
+ painter.setPen(Qt::NoPen);
+//! [15] //! [16]
+ painter.setBrush(hourColor);
+//! [16]
+
+//! [17] //! [18]
+ painter.save();
+//! [17] //! [19]
+ painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
+ painter.drawConvexPolygon(hourHand, 3);
+ painter.restore();
+//! [18] //! [19]
+
+//! [20]
+ painter.setPen(hourColor);
+//! [20] //! [21]
+
+ for (int i = 0; i < 12; ++i) {
+ painter.drawLine(88, 0, 96, 0);
+ painter.rotate(30.0);
+ }
+//! [21]
+
+//! [22]
+ painter.setPen(Qt::NoPen);
+//! [22] //! [23]
+ painter.setBrush(minuteColor);
+
+//! [24]
+ painter.save();
+ painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
+ painter.drawConvexPolygon(minuteHand, 3);
+ painter.restore();
+//! [23] //! [24]
+
+//! [25]
+ painter.setPen(minuteColor);
+//! [25] //! [26]
+
+//! [27]
+ for (int j = 0; j < 60; ++j) {
+ if ((j % 5) != 0)
+ painter.drawLine(92, 0, 96, 0);
+ painter.rotate(6.0);
+ }
+//! [27]
+}
+//! [26]
diff --git a/examples/widgets/analogclock/analogclock.h b/examples/widgets/analogclock/analogclock.h
new file mode 100644
index 0000000000..5da2780f62
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ANALOGCLOCK_H
+#define ANALOGCLOCK_H
+
+#include <QWidget>
+
+//! [0]
+class AnalogClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ AnalogClock(QWidget *parent = 0);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/analogclock/analogclock.pro b/examples/widgets/analogclock/analogclock.pro
new file mode 100644
index 0000000000..3183fe0eab
--- /dev/null
+++ b/examples/widgets/analogclock/analogclock.pro
@@ -0,0 +1,14 @@
+HEADERS = analogclock.h
+SOURCES = analogclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/analogclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS analogclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/analogclock
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000A64F
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/analogclock/main.cpp b/examples/widgets/analogclock/main.cpp
new file mode 100644
index 0000000000..0f31f07573
--- /dev/null
+++ b/examples/widgets/analogclock/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "analogclock.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ AnalogClock clock;
+ clock.show();
+ return app.exec();
+}
diff --git a/examples/widgets/calculator/button.cpp b/examples/widgets/calculator/button.cpp
new file mode 100644
index 0000000000..7bd1783801
--- /dev/null
+++ b/examples/widgets/calculator/button.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "button.h"
+
+//! [0]
+Button::Button(const QString &text, QWidget *parent)
+ : QToolButton(parent)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ setText(text);
+}
+//! [0]
+
+//! [1]
+QSize Button::sizeHint() const
+//! [1] //! [2]
+{
+ QSize size = QToolButton::sizeHint();
+ size.rheight() += 20;
+ size.rwidth() = qMax(size.width(), size.height());
+ return size;
+}
+//! [2]
diff --git a/examples/widgets/calculator/button.h b/examples/widgets/calculator/button.h
new file mode 100644
index 0000000000..385c1db7df
--- /dev/null
+++ b/examples/widgets/calculator/button.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BUTTON_H
+#define BUTTON_H
+
+#include <QToolButton>
+
+//! [0]
+class Button : public QToolButton
+{
+ Q_OBJECT
+
+public:
+ Button(const QString &text, QWidget *parent = 0);
+
+ QSize sizeHint() const;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/calculator/calculator.cpp b/examples/widgets/calculator/calculator.cpp
new file mode 100644
index 0000000000..991ffc3efc
--- /dev/null
+++ b/examples/widgets/calculator/calculator.cpp
@@ -0,0 +1,397 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <math.h>
+
+#include "button.h"
+#include "calculator.h"
+
+//! [0]
+Calculator::Calculator(QWidget *parent)
+ : QDialog(parent)
+{
+ sumInMemory = 0.0;
+ sumSoFar = 0.0;
+ factorSoFar = 0.0;
+ waitingForOperand = true;
+//! [0]
+
+//! [1]
+ display = new QLineEdit("0");
+//! [1] //! [2]
+ display->setReadOnly(true);
+ display->setAlignment(Qt::AlignRight);
+ display->setMaxLength(15);
+
+ QFont font = display->font();
+ font.setPointSize(font.pointSize() + 8);
+ display->setFont(font);
+//! [2]
+
+//! [4]
+ for (int i = 0; i < NumDigitButtons; ++i) {
+ digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked()));
+ }
+
+ Button *pointButton = createButton(tr("."), SLOT(pointClicked()));
+ Button *changeSignButton = createButton(tr("\261"), SLOT(changeSignClicked()));
+
+ Button *backspaceButton = createButton(tr("Backspace"), SLOT(backspaceClicked()));
+ Button *clearButton = createButton(tr("Clear"), SLOT(clear()));
+ Button *clearAllButton = createButton(tr("Clear All"), SLOT(clearAll()));
+
+ Button *clearMemoryButton = createButton(tr("MC"), SLOT(clearMemory()));
+ Button *readMemoryButton = createButton(tr("MR"), SLOT(readMemory()));
+ Button *setMemoryButton = createButton(tr("MS"), SLOT(setMemory()));
+ Button *addToMemoryButton = createButton(tr("M+"), SLOT(addToMemory()));
+
+ Button *divisionButton = createButton(tr("\367"), SLOT(multiplicativeOperatorClicked()));
+ Button *timesButton = createButton(tr("\327"), SLOT(multiplicativeOperatorClicked()));
+ Button *minusButton = createButton(tr("-"), SLOT(additiveOperatorClicked()));
+ Button *plusButton = createButton(tr("+"), SLOT(additiveOperatorClicked()));
+
+ Button *squareRootButton = createButton(tr("Sqrt"), SLOT(unaryOperatorClicked()));
+ Button *powerButton = createButton(tr("x\262"), SLOT(unaryOperatorClicked()));
+ Button *reciprocalButton = createButton(tr("1/x"), SLOT(unaryOperatorClicked()));
+ Button *equalButton = createButton(tr("="), SLOT(equalClicked()));
+//! [4]
+
+//! [5]
+ QGridLayout *mainLayout = new QGridLayout;
+//! [5] //! [6]
+ mainLayout->setSizeConstraint(QLayout::SetFixedSize);
+
+ mainLayout->addWidget(display, 0, 0, 1, 6);
+ mainLayout->addWidget(backspaceButton, 1, 0, 1, 2);
+ mainLayout->addWidget(clearButton, 1, 2, 1, 2);
+ mainLayout->addWidget(clearAllButton, 1, 4, 1, 2);
+
+ mainLayout->addWidget(clearMemoryButton, 2, 0);
+ mainLayout->addWidget(readMemoryButton, 3, 0);
+ mainLayout->addWidget(setMemoryButton, 4, 0);
+ mainLayout->addWidget(addToMemoryButton, 5, 0);
+
+ for (int i = 1; i < NumDigitButtons; ++i) {
+ int row = ((9 - i) / 3) + 2;
+ int column = ((i - 1) % 3) + 1;
+ mainLayout->addWidget(digitButtons[i], row, column);
+ }
+
+ mainLayout->addWidget(digitButtons[0], 5, 1);
+ mainLayout->addWidget(pointButton, 5, 2);
+ mainLayout->addWidget(changeSignButton, 5, 3);
+
+ mainLayout->addWidget(divisionButton, 2, 4);
+ mainLayout->addWidget(timesButton, 3, 4);
+ mainLayout->addWidget(minusButton, 4, 4);
+ mainLayout->addWidget(plusButton, 5, 4);
+
+ mainLayout->addWidget(squareRootButton, 2, 5);
+ mainLayout->addWidget(powerButton, 3, 5);
+ mainLayout->addWidget(reciprocalButton, 4, 5);
+ mainLayout->addWidget(equalButton, 5, 5);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Calculator"));
+}
+//! [6]
+
+//! [7]
+void Calculator::digitClicked()
+{
+ Button *clickedButton = qobject_cast<Button *>(sender());
+ int digitValue = clickedButton->text().toInt();
+ if (display->text() == "0" && digitValue == 0.0)
+ return;
+
+ if (waitingForOperand) {
+ display->clear();
+ waitingForOperand = false;
+ }
+ display->setText(display->text() + QString::number(digitValue));
+}
+//! [7]
+
+//! [8]
+void Calculator::unaryOperatorClicked()
+//! [8] //! [9]
+{
+ Button *clickedButton = qobject_cast<Button *>(sender());
+ QString clickedOperator = clickedButton->text();
+ double operand = display->text().toDouble();
+ double result = 0.0;
+
+ if (clickedOperator == tr("Sqrt")) {
+ if (operand < 0.0) {
+ abortOperation();
+ return;
+ }
+ result = sqrt(operand);
+ } else if (clickedOperator == tr("x\262")) {
+ result = pow(operand, 2.0);
+ } else if (clickedOperator == tr("1/x")) {
+ if (operand == 0.0) {
+ abortOperation();
+ return;
+ }
+ result = 1.0 / operand;
+ }
+ display->setText(QString::number(result));
+ waitingForOperand = true;
+}
+//! [9]
+
+//! [10]
+void Calculator::additiveOperatorClicked()
+//! [10] //! [11]
+{
+ Button *clickedButton = qobject_cast<Button *>(sender());
+ QString clickedOperator = clickedButton->text();
+ double operand = display->text().toDouble();
+
+//! [11] //! [12]
+ if (!pendingMultiplicativeOperator.isEmpty()) {
+//! [12] //! [13]
+ if (!calculate(operand, pendingMultiplicativeOperator)) {
+ abortOperation();
+ return;
+ }
+ display->setText(QString::number(factorSoFar));
+ operand = factorSoFar;
+ factorSoFar = 0.0;
+ pendingMultiplicativeOperator.clear();
+ }
+
+//! [13] //! [14]
+ if (!pendingAdditiveOperator.isEmpty()) {
+//! [14] //! [15]
+ if (!calculate(operand, pendingAdditiveOperator)) {
+ abortOperation();
+ return;
+ }
+ display->setText(QString::number(sumSoFar));
+ } else {
+ sumSoFar = operand;
+ }
+
+//! [15] //! [16]
+ pendingAdditiveOperator = clickedOperator;
+//! [16] //! [17]
+ waitingForOperand = true;
+}
+//! [17]
+
+//! [18]
+void Calculator::multiplicativeOperatorClicked()
+{
+ Button *clickedButton = qobject_cast<Button *>(sender());
+ QString clickedOperator = clickedButton->text();
+ double operand = display->text().toDouble();
+
+ if (!pendingMultiplicativeOperator.isEmpty()) {
+ if (!calculate(operand, pendingMultiplicativeOperator)) {
+ abortOperation();
+ return;
+ }
+ display->setText(QString::number(factorSoFar));
+ } else {
+ factorSoFar = operand;
+ }
+
+ pendingMultiplicativeOperator = clickedOperator;
+ waitingForOperand = true;
+}
+//! [18]
+
+//! [20]
+void Calculator::equalClicked()
+{
+ double operand = display->text().toDouble();
+
+ if (!pendingMultiplicativeOperator.isEmpty()) {
+ if (!calculate(operand, pendingMultiplicativeOperator)) {
+ abortOperation();
+ return;
+ }
+ operand = factorSoFar;
+ factorSoFar = 0.0;
+ pendingMultiplicativeOperator.clear();
+ }
+ if (!pendingAdditiveOperator.isEmpty()) {
+ if (!calculate(operand, pendingAdditiveOperator)) {
+ abortOperation();
+ return;
+ }
+ pendingAdditiveOperator.clear();
+ } else {
+ sumSoFar = operand;
+ }
+
+ display->setText(QString::number(sumSoFar));
+ sumSoFar = 0.0;
+ waitingForOperand = true;
+}
+//! [20]
+
+//! [22]
+void Calculator::pointClicked()
+{
+ if (waitingForOperand)
+ display->setText("0");
+ if (!display->text().contains("."))
+ display->setText(display->text() + tr("."));
+ waitingForOperand = false;
+}
+//! [22]
+
+//! [24]
+void Calculator::changeSignClicked()
+{
+ QString text = display->text();
+ double value = text.toDouble();
+
+ if (value > 0.0) {
+ text.prepend(tr("-"));
+ } else if (value < 0.0) {
+ text.remove(0, 1);
+ }
+ display->setText(text);
+}
+//! [24]
+
+//! [26]
+void Calculator::backspaceClicked()
+{
+ if (waitingForOperand)
+ return;
+
+ QString text = display->text();
+ text.chop(1);
+ if (text.isEmpty()) {
+ text = "0";
+ waitingForOperand = true;
+ }
+ display->setText(text);
+}
+//! [26]
+
+//! [28]
+void Calculator::clear()
+{
+ if (waitingForOperand)
+ return;
+
+ display->setText("0");
+ waitingForOperand = true;
+}
+//! [28]
+
+//! [30]
+void Calculator::clearAll()
+{
+ sumSoFar = 0.0;
+ factorSoFar = 0.0;
+ pendingAdditiveOperator.clear();
+ pendingMultiplicativeOperator.clear();
+ display->setText("0");
+ waitingForOperand = true;
+}
+//! [30]
+
+//! [32]
+void Calculator::clearMemory()
+{
+ sumInMemory = 0.0;
+}
+
+void Calculator::readMemory()
+{
+ display->setText(QString::number(sumInMemory));
+ waitingForOperand = true;
+}
+
+void Calculator::setMemory()
+{
+ equalClicked();
+ sumInMemory = display->text().toDouble();
+}
+
+void Calculator::addToMemory()
+{
+ equalClicked();
+ sumInMemory += display->text().toDouble();
+}
+//! [32]
+//! [34]
+Button *Calculator::createButton(const QString &text, const char *member)
+{
+ Button *button = new Button(text);
+ connect(button, SIGNAL(clicked()), this, member);
+ return button;
+}
+//! [34]
+
+//! [36]
+void Calculator::abortOperation()
+{
+ clearAll();
+ display->setText(tr("####"));
+}
+//! [36]
+
+//! [38]
+bool Calculator::calculate(double rightOperand, const QString &pendingOperator)
+{
+ if (pendingOperator == tr("+")) {
+ sumSoFar += rightOperand;
+ } else if (pendingOperator == tr("-")) {
+ sumSoFar -= rightOperand;
+ } else if (pendingOperator == tr("\327")) {
+ factorSoFar *= rightOperand;
+ } else if (pendingOperator == tr("\367")) {
+ if (rightOperand == 0.0)
+ return false;
+ factorSoFar /= rightOperand;
+ }
+ return true;
+}
+//! [38]
diff --git a/examples/widgets/calculator/calculator.h b/examples/widgets/calculator/calculator.h
new file mode 100644
index 0000000000..e1221f4f70
--- /dev/null
+++ b/examples/widgets/calculator/calculator.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CALCULATOR_H
+#define CALCULATOR_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+QT_END_NAMESPACE
+class Button;
+
+//! [0]
+class Calculator : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Calculator(QWidget *parent = 0);
+
+private slots:
+ void digitClicked();
+ void unaryOperatorClicked();
+ void additiveOperatorClicked();
+ void multiplicativeOperatorClicked();
+ void equalClicked();
+ void pointClicked();
+ void changeSignClicked();
+ void backspaceClicked();
+ void clear();
+ void clearAll();
+ void clearMemory();
+ void readMemory();
+ void setMemory();
+ void addToMemory();
+//! [0]
+
+//! [1]
+private:
+//! [1] //! [2]
+ Button *createButton(const QString &text, const char *member);
+ void abortOperation();
+ bool calculate(double rightOperand, const QString &pendingOperator);
+//! [2]
+
+//! [3]
+ double sumInMemory;
+//! [3] //! [4]
+ double sumSoFar;
+//! [4] //! [5]
+ double factorSoFar;
+//! [5] //! [6]
+ QString pendingAdditiveOperator;
+//! [6] //! [7]
+ QString pendingMultiplicativeOperator;
+//! [7] //! [8]
+ bool waitingForOperand;
+//! [8]
+
+//! [9]
+ QLineEdit *display;
+//! [9] //! [10]
+
+ enum { NumDigitButtons = 10 };
+ Button *digitButtons[NumDigitButtons];
+};
+//! [10]
+
+#endif
diff --git a/examples/widgets/calculator/calculator.pro b/examples/widgets/calculator/calculator.pro
new file mode 100644
index 0000000000..958661736e
--- /dev/null
+++ b/examples/widgets/calculator/calculator.pro
@@ -0,0 +1,16 @@
+HEADERS = button.h \
+ calculator.h
+SOURCES = button.cpp \
+ calculator.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/calculator
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calculator.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/calculator
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C602
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/calculator/main.cpp b/examples/widgets/calculator/main.cpp
new file mode 100644
index 0000000000..0038aa10dd
--- /dev/null
+++ b/examples/widgets/calculator/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "calculator.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ Calculator calc;
+ calc.show();
+ return app.exec();
+}
diff --git a/examples/widgets/calendarwidget/calendarwidget.pro b/examples/widgets/calendarwidget/calendarwidget.pro
new file mode 100644
index 0000000000..9922266200
--- /dev/null
+++ b/examples/widgets/calendarwidget/calendarwidget.pro
@@ -0,0 +1,14 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/calendarwidget
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendarwidget.pro resources
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/calendarwidget
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C603
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/calendarwidget/main.cpp b/examples/widgets/calendarwidget/main.cpp
new file mode 100644
index 0000000000..b14a44f7c6
--- /dev/null
+++ b/examples/widgets/calendarwidget/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#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/calendarwidget/window.cpp b/examples/widgets/calendarwidget/window.cpp
new file mode 100644
index 0000000000..ad8e63c3ec
--- /dev/null
+++ b/examples/widgets/calendarwidget/window.cpp
@@ -0,0 +1,461 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ createPreviewGroupBox();
+ createGeneralOptionsGroupBox();
+ createDatesGroupBox();
+ createTextFormatsGroupBox();
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(previewGroupBox, 0, 0);
+ layout->addWidget(generalOptionsGroupBox, 0, 1);
+ layout->addWidget(datesGroupBox, 1, 0);
+ layout->addWidget(textFormatsGroupBox, 1, 1);
+ layout->setSizeConstraint(QLayout::SetFixedSize);
+ setLayout(layout);
+
+ previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height());
+ previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width());
+
+ setWindowTitle(tr("Calendar Widget"));
+}
+//! [0]
+
+void Window::localeChanged(int index)
+{
+ calendar->setLocale(localeCombo->itemData(index).toLocale());
+}
+
+//! [1]
+void Window::firstDayChanged(int index)
+{
+ calendar->setFirstDayOfWeek(Qt::DayOfWeek(
+ firstDayCombo->itemData(index).toInt()));
+}
+//! [1]
+
+void Window::selectionModeChanged(int index)
+{
+ calendar->setSelectionMode(QCalendarWidget::SelectionMode(
+ selectionModeCombo->itemData(index).toInt()));
+}
+
+void Window::horizontalHeaderChanged(int index)
+{
+ calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat(
+ horizontalHeaderCombo->itemData(index).toInt()));
+}
+
+void Window::verticalHeaderChanged(int index)
+{
+ calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat(
+ verticalHeaderCombo->itemData(index).toInt()));
+}
+
+//! [2]
+void Window::selectedDateChanged()
+{
+ currentDateEdit->setDate(calendar->selectedDate());
+}
+//! [2]
+
+//! [3]
+void Window::minimumDateChanged(const QDate &date)
+{
+ calendar->setMinimumDate(date);
+ maximumDateEdit->setDate(calendar->maximumDate());
+}
+//! [3]
+
+//! [4]
+void Window::maximumDateChanged(const QDate &date)
+{
+ calendar->setMaximumDate(date);
+ minimumDateEdit->setDate(calendar->minimumDate());
+}
+//! [4]
+
+//! [5]
+void Window::weekdayFormatChanged()
+{
+ QTextCharFormat format;
+
+ format.setForeground(qvariant_cast<QColor>(
+ weekdayColorCombo->itemData(weekdayColorCombo->currentIndex())));
+ calendar->setWeekdayTextFormat(Qt::Monday, format);
+ calendar->setWeekdayTextFormat(Qt::Tuesday, format);
+ calendar->setWeekdayTextFormat(Qt::Wednesday, format);
+ calendar->setWeekdayTextFormat(Qt::Thursday, format);
+ calendar->setWeekdayTextFormat(Qt::Friday, format);
+}
+//! [5]
+
+//! [6]
+void Window::weekendFormatChanged()
+{
+ QTextCharFormat format;
+
+ format.setForeground(qvariant_cast<QColor>(
+ weekendColorCombo->itemData(weekendColorCombo->currentIndex())));
+ calendar->setWeekdayTextFormat(Qt::Saturday, format);
+ calendar->setWeekdayTextFormat(Qt::Sunday, format);
+}
+//! [6]
+
+//! [7]
+void Window::reformatHeaders()
+{
+ QString text = headerTextFormatCombo->currentText();
+ QTextCharFormat format;
+
+ if (text == tr("Bold")) {
+ format.setFontWeight(QFont::Bold);
+ } else if (text == tr("Italic")) {
+ format.setFontItalic(true);
+ } else if (text == tr("Green")) {
+ format.setForeground(Qt::green);
+ }
+ calendar->setHeaderTextFormat(format);
+}
+//! [7]
+
+//! [8]
+void Window::reformatCalendarPage()
+{
+ if (firstFridayCheckBox->isChecked()) {
+ QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1);
+ while (firstFriday.dayOfWeek() != Qt::Friday)
+ firstFriday = firstFriday.addDays(1);
+ QTextCharFormat firstFridayFormat;
+ firstFridayFormat.setForeground(Qt::blue);
+ calendar->setDateTextFormat(firstFriday, firstFridayFormat);
+ }
+
+ //May First in Red takes precedence
+ if (mayFirstCheckBox->isChecked()) {
+ const QDate mayFirst(calendar->yearShown(), 5, 1);
+ QTextCharFormat mayFirstFormat;
+ mayFirstFormat.setForeground(Qt::red);
+ calendar->setDateTextFormat(mayFirst, mayFirstFormat);
+ }
+}
+//! [8]
+
+//! [9]
+void Window::createPreviewGroupBox()
+{
+ previewGroupBox = new QGroupBox(tr("Preview"));
+
+ calendar = new QCalendarWidget;
+ calendar->setMinimumDate(QDate(1900, 1, 1));
+ calendar->setMaximumDate(QDate(3000, 1, 1));
+ calendar->setGridVisible(true);
+
+ connect(calendar, SIGNAL(currentPageChanged(int,int)),
+ this, SLOT(reformatCalendarPage()));
+
+ previewLayout = new QGridLayout;
+ previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter);
+ previewGroupBox->setLayout(previewLayout);
+}
+//! [9]
+
+//! [10]
+void Window::createGeneralOptionsGroupBox()
+{
+ generalOptionsGroupBox = new QGroupBox(tr("General Options"));
+
+ localeCombo = new QComboBox;
+ int curLocaleIndex = -1;
+ int index = 0;
+ for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
+ QLocale::Language lang = static_cast<QLocale::Language>(_lang);
+ QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
+ for (int i = 0; i < countries.count(); ++i) {
+ QLocale::Country country = countries.at(i);
+ QString label = QLocale::languageToString(lang);
+ label += QLatin1Char('/');
+ label += QLocale::countryToString(country);
+ QLocale locale(lang, country);
+ if (this->locale().language() == lang && this->locale().country() == country)
+ curLocaleIndex = index;
+ localeCombo->addItem(label, locale);
+ ++index;
+ }
+ }
+ if (curLocaleIndex != -1)
+ localeCombo->setCurrentIndex(curLocaleIndex);
+ localeLabel = new QLabel(tr("&Locale"));
+ localeLabel->setBuddy(localeCombo);
+
+ firstDayCombo = new QComboBox;
+ firstDayCombo->addItem(tr("Sunday"), Qt::Sunday);
+ firstDayCombo->addItem(tr("Monday"), Qt::Monday);
+ firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday);
+ firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday);
+ firstDayCombo->addItem(tr("Thursday"), Qt::Thursday);
+ firstDayCombo->addItem(tr("Friday"), Qt::Friday);
+ firstDayCombo->addItem(tr("Saturday"), Qt::Saturday);
+
+ firstDayLabel = new QLabel(tr("Wee&k starts on:"));
+ firstDayLabel->setBuddy(firstDayCombo);
+//! [10]
+
+ selectionModeCombo = new QComboBox;
+ selectionModeCombo->addItem(tr("Single selection"),
+ QCalendarWidget::SingleSelection);
+ selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection);
+
+ selectionModeLabel = new QLabel(tr("&Selection mode:"));
+ selectionModeLabel->setBuddy(selectionModeCombo);
+
+ gridCheckBox = new QCheckBox(tr("&Grid"));
+ gridCheckBox->setChecked(calendar->isGridVisible());
+
+ navigationCheckBox = new QCheckBox(tr("&Navigation bar"));
+ navigationCheckBox->setChecked(true);
+
+ horizontalHeaderCombo = new QComboBox;
+ horizontalHeaderCombo->addItem(tr("Single letter day names"),
+ QCalendarWidget::SingleLetterDayNames);
+ horizontalHeaderCombo->addItem(tr("Short day names"),
+ QCalendarWidget::ShortDayNames);
+ horizontalHeaderCombo->addItem(tr("None"),
+ QCalendarWidget::NoHorizontalHeader);
+ horizontalHeaderCombo->setCurrentIndex(1);
+
+ horizontalHeaderLabel = new QLabel(tr("&Horizontal header:"));
+ horizontalHeaderLabel->setBuddy(horizontalHeaderCombo);
+
+ verticalHeaderCombo = new QComboBox;
+ verticalHeaderCombo->addItem(tr("ISO week numbers"),
+ QCalendarWidget::ISOWeekNumbers);
+ verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader);
+
+ verticalHeaderLabel = new QLabel(tr("&Vertical header:"));
+ verticalHeaderLabel->setBuddy(verticalHeaderCombo);
+
+//! [11]
+ connect(localeCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(localeChanged(int)));
+ connect(firstDayCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(firstDayChanged(int)));
+ connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(selectionModeChanged(int)));
+ connect(gridCheckBox, SIGNAL(toggled(bool)),
+ calendar, SLOT(setGridVisible(bool)));
+ connect(navigationCheckBox, SIGNAL(toggled(bool)),
+ calendar, SLOT(setNavigationBarVisible(bool)));
+ connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(horizontalHeaderChanged(int)));
+ connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(verticalHeaderChanged(int)));
+//! [11]
+
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(gridCheckBox);
+ checkBoxLayout->addStretch();
+ checkBoxLayout->addWidget(navigationCheckBox);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(localeLabel, 0, 0);
+ outerLayout->addWidget(localeCombo, 0, 1);
+ outerLayout->addWidget(firstDayLabel, 1, 0);
+ outerLayout->addWidget(firstDayCombo, 1, 1);
+ outerLayout->addWidget(selectionModeLabel, 2, 0);
+ outerLayout->addWidget(selectionModeCombo, 2, 1);
+ outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ outerLayout->addWidget(horizontalHeaderLabel, 4, 0);
+ outerLayout->addWidget(horizontalHeaderCombo, 4, 1);
+ outerLayout->addWidget(verticalHeaderLabel, 5, 0);
+ outerLayout->addWidget(verticalHeaderCombo, 5, 1);
+ generalOptionsGroupBox->setLayout(outerLayout);
+
+//! [12]
+ firstDayChanged(firstDayCombo->currentIndex());
+ selectionModeChanged(selectionModeCombo->currentIndex());
+ horizontalHeaderChanged(horizontalHeaderCombo->currentIndex());
+ verticalHeaderChanged(verticalHeaderCombo->currentIndex());
+}
+//! [12]
+
+//! [13]
+void Window::createDatesGroupBox()
+{
+ datesGroupBox = new QGroupBox(tr("Dates"));
+
+ minimumDateEdit = new QDateEdit;
+ minimumDateEdit->setDisplayFormat("MMM d yyyy");
+ minimumDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+ minimumDateEdit->setDate(calendar->minimumDate());
+
+ minimumDateLabel = new QLabel(tr("&Minimum Date:"));
+ minimumDateLabel->setBuddy(minimumDateEdit);
+
+ currentDateEdit = new QDateEdit;
+ currentDateEdit->setDisplayFormat("MMM d yyyy");
+ currentDateEdit->setDate(calendar->selectedDate());
+ currentDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+
+ currentDateLabel = new QLabel(tr("&Current Date:"));
+ currentDateLabel->setBuddy(currentDateEdit);
+
+ maximumDateEdit = new QDateEdit;
+ maximumDateEdit->setDisplayFormat("MMM d yyyy");
+ maximumDateEdit->setDateRange(calendar->minimumDate(),
+ calendar->maximumDate());
+ maximumDateEdit->setDate(calendar->maximumDate());
+
+ maximumDateLabel = new QLabel(tr("Ma&ximum Date:"));
+ maximumDateLabel->setBuddy(maximumDateEdit);
+
+//! [13] //! [14]
+ connect(currentDateEdit, SIGNAL(dateChanged(QDate)),
+ calendar, SLOT(setSelectedDate(QDate)));
+ connect(calendar, SIGNAL(selectionChanged()),
+ this, SLOT(selectedDateChanged()));
+ connect(minimumDateEdit, SIGNAL(dateChanged(QDate)),
+ this, SLOT(minimumDateChanged(QDate)));
+ connect(maximumDateEdit, SIGNAL(dateChanged(QDate)),
+ this, SLOT(maximumDateChanged(QDate)));
+
+//! [14]
+ QGridLayout *dateBoxLayout = new QGridLayout;
+ dateBoxLayout->addWidget(currentDateLabel, 1, 0);
+ dateBoxLayout->addWidget(currentDateEdit, 1, 1);
+ dateBoxLayout->addWidget(minimumDateLabel, 0, 0);
+ dateBoxLayout->addWidget(minimumDateEdit, 0, 1);
+ dateBoxLayout->addWidget(maximumDateLabel, 2, 0);
+ dateBoxLayout->addWidget(maximumDateEdit, 2, 1);
+ dateBoxLayout->setRowStretch(3, 1);
+
+ datesGroupBox->setLayout(dateBoxLayout);
+//! [15]
+}
+//! [15]
+
+//! [16]
+void Window::createTextFormatsGroupBox()
+{
+ textFormatsGroupBox = new QGroupBox(tr("Text Formats"));
+
+ weekdayColorCombo = createColorComboBox();
+ weekdayColorCombo->setCurrentIndex(
+ weekdayColorCombo->findText(tr("Black")));
+
+ weekdayColorLabel = new QLabel(tr("&Weekday color:"));
+ weekdayColorLabel->setBuddy(weekdayColorCombo);
+
+ weekendColorCombo = createColorComboBox();
+ weekendColorCombo->setCurrentIndex(
+ weekendColorCombo->findText(tr("Red")));
+
+ weekendColorLabel = new QLabel(tr("Week&end color:"));
+ weekendColorLabel->setBuddy(weekendColorCombo);
+
+//! [16] //! [17]
+ headerTextFormatCombo = new QComboBox;
+ headerTextFormatCombo->addItem(tr("Bold"));
+ headerTextFormatCombo->addItem(tr("Italic"));
+ headerTextFormatCombo->addItem(tr("Plain"));
+
+ headerTextFormatLabel = new QLabel(tr("&Header text:"));
+ headerTextFormatLabel->setBuddy(headerTextFormatCombo);
+
+ firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue"));
+
+ mayFirstCheckBox = new QCheckBox(tr("May &1 in red"));
+
+//! [17] //! [18]
+ connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(weekdayFormatChanged()));
+ connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(weekendFormatChanged()));
+ connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)),
+ this, SLOT(reformatHeaders()));
+ connect(firstFridayCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(reformatCalendarPage()));
+ connect(mayFirstCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(reformatCalendarPage()));
+
+//! [18]
+ QHBoxLayout *checkBoxLayout = new QHBoxLayout;
+ checkBoxLayout->addWidget(firstFridayCheckBox);
+ checkBoxLayout->addStretch();
+ checkBoxLayout->addWidget(mayFirstCheckBox);
+
+ QGridLayout *outerLayout = new QGridLayout;
+ outerLayout->addWidget(weekdayColorLabel, 0, 0);
+ outerLayout->addWidget(weekdayColorCombo, 0, 1);
+ outerLayout->addWidget(weekendColorLabel, 1, 0);
+ outerLayout->addWidget(weekendColorCombo, 1, 1);
+ outerLayout->addWidget(headerTextFormatLabel, 2, 0);
+ outerLayout->addWidget(headerTextFormatCombo, 2, 1);
+ outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2);
+ textFormatsGroupBox->setLayout(outerLayout);
+
+ weekdayFormatChanged();
+ weekendFormatChanged();
+//! [19]
+ reformatHeaders();
+ reformatCalendarPage();
+}
+//! [19]
+
+//! [20]
+QComboBox *Window::createColorComboBox()
+{
+ QComboBox *comboBox = new QComboBox;
+ comboBox->addItem(tr("Red"), Qt::red);
+ comboBox->addItem(tr("Blue"), Qt::blue);
+ comboBox->addItem(tr("Black"), Qt::black);
+ comboBox->addItem(tr("Magenta"), Qt::magenta);
+ return comboBox;
+}
+//! [20]
diff --git a/examples/widgets/calendarwidget/window.h b/examples/widgets/calendarwidget/window.h
new file mode 100644
index 0000000000..55f2963189
--- /dev/null
+++ b/examples/widgets/calendarwidget/window.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCalendarWidget;
+class QCheckBox;
+class QComboBox;
+class QDate;
+class QDateEdit;
+class QGridLayout;
+class QGroupBox;
+class QLabel;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private slots:
+ void localeChanged(int index);
+ void firstDayChanged(int index);
+ void selectionModeChanged(int index);
+ void horizontalHeaderChanged(int index);
+ void verticalHeaderChanged(int index);
+ void selectedDateChanged();
+ void minimumDateChanged(const QDate &date);
+ void maximumDateChanged(const QDate &date);
+ void weekdayFormatChanged();
+ void weekendFormatChanged();
+ void reformatHeaders();
+ void reformatCalendarPage();
+
+private:
+ void createPreviewGroupBox();
+ void createGeneralOptionsGroupBox();
+ void createDatesGroupBox();
+ void createTextFormatsGroupBox();
+ QComboBox *createColorComboBox();
+
+ QGroupBox *previewGroupBox;
+ QGridLayout *previewLayout;
+ QCalendarWidget *calendar;
+
+ QGroupBox *generalOptionsGroupBox;
+ QLabel *localeLabel;
+ QLabel *firstDayLabel;
+//! [0]
+ QLabel *selectionModeLabel;
+ QLabel *horizontalHeaderLabel;
+ QLabel *verticalHeaderLabel;
+ QComboBox *localeCombo;
+ QComboBox *firstDayCombo;
+ QComboBox *selectionModeCombo;
+ QCheckBox *gridCheckBox;
+ QCheckBox *navigationCheckBox;
+ QComboBox *horizontalHeaderCombo;
+ QComboBox *verticalHeaderCombo;
+
+ QGroupBox *datesGroupBox;
+ QLabel *currentDateLabel;
+ QLabel *minimumDateLabel;
+ QLabel *maximumDateLabel;
+ QDateEdit *currentDateEdit;
+ QDateEdit *minimumDateEdit;
+ QDateEdit *maximumDateEdit;
+
+ QGroupBox *textFormatsGroupBox;
+ QLabel *weekdayColorLabel;
+ QLabel *weekendColorLabel;
+ QLabel *headerTextFormatLabel;
+ QComboBox *weekdayColorCombo;
+ QComboBox *weekendColorCombo;
+ QComboBox *headerTextFormatCombo;
+
+ QCheckBox *firstFridayCheckBox;
+//! [1]
+ QCheckBox *mayFirstCheckBox;
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/charactermap/charactermap.pro b/examples/widgets/charactermap/charactermap.pro
new file mode 100644
index 0000000000..290e7d6379
--- /dev/null
+++ b/examples/widgets/charactermap/charactermap.pro
@@ -0,0 +1,13 @@
+HEADERS = characterwidget.h \
+ mainwindow.h
+SOURCES = characterwidget.cpp \
+ mainwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/charactermap
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS charactermap.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/charactermap
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/charactermap/characterwidget.cpp b/examples/widgets/charactermap/characterwidget.cpp
new file mode 100644
index 0000000000..d9a59b68b2
--- /dev/null
+++ b/examples/widgets/charactermap/characterwidget.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "characterwidget.h"
+
+//! [0]
+CharacterWidget::CharacterWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ squareSize = 24;
+ columns = 16;
+ lastKey = -1;
+ setMouseTracking(true);
+}
+//! [0]
+
+//! [1]
+void CharacterWidget::updateFont(const QFont &font)
+{
+ displayFont.setFamily(font.family());
+ squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ adjustSize();
+ update();
+}
+//! [1]
+
+//! [2]
+void CharacterWidget::updateSize(const QString &fontSize)
+{
+ displayFont.setPointSize(fontSize.toInt());
+ squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ adjustSize();
+ update();
+}
+//! [2]
+
+void CharacterWidget::updateStyle(const QString &fontStyle)
+{
+ QFontDatabase fontDatabase;
+ const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy();
+ displayFont = fontDatabase.font(displayFont.family(), fontStyle, displayFont.pointSize());
+ displayFont.setStyleStrategy(oldStrategy);
+ squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ adjustSize();
+ update();
+}
+
+void CharacterWidget::updateFontMerging(bool enable)
+{
+ if (enable)
+ displayFont.setStyleStrategy(QFont::PreferDefault);
+ else
+ displayFont.setStyleStrategy(QFont::NoFontMerging);
+ adjustSize();
+ update();
+}
+
+//! [3]
+QSize CharacterWidget::sizeHint() const
+{
+ return QSize(columns*squareSize, (65536/columns)*squareSize);
+}
+//! [3]
+
+//! [4]
+void CharacterWidget::mouseMoveEvent(QMouseEvent *event)
+{
+ QPoint widgetPosition = mapFromGlobal(event->globalPos());
+ uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize;
+
+ QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family())
+ + QChar(key)
+ + QString::fromLatin1("</span><p>Value: 0x")
+ + QString::number(key, 16);
+ QToolTip::showText(event->globalPos(), text, this);
+}
+//! [4]
+
+//! [5]
+void CharacterWidget::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ lastKey = (event->y()/squareSize)*columns + event->x()/squareSize;
+ if (QChar(lastKey).category() != QChar::NoCategory)
+ emit characterSelected(QString(QChar(lastKey)));
+ update();
+ }
+ else
+ QWidget::mousePressEvent(event);
+}
+//! [5]
+
+//! [6]
+void CharacterWidget::paintEvent(QPaintEvent *event)
+{
+ QPainter painter(this);
+ painter.fillRect(event->rect(), QBrush(Qt::white));
+ painter.setFont(displayFont);
+//! [6]
+
+//! [7]
+ QRect redrawRect = event->rect();
+ int beginRow = redrawRect.top()/squareSize;
+ int endRow = redrawRect.bottom()/squareSize;
+ int beginColumn = redrawRect.left()/squareSize;
+ int endColumn = redrawRect.right()/squareSize;
+//! [7]
+
+//! [8]
+ painter.setPen(QPen(Qt::gray));
+ for (int row = beginRow; row <= endRow; ++row) {
+ for (int column = beginColumn; column <= endColumn; ++column) {
+ painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize);
+ }
+//! [8] //! [9]
+ }
+//! [9]
+
+//! [10]
+ QFontMetrics fontMetrics(displayFont);
+ painter.setPen(QPen(Qt::black));
+ for (int row = beginRow; row <= endRow; ++row) {
+
+ for (int column = beginColumn; column <= endColumn; ++column) {
+
+ int key = row*columns + column;
+ painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize);
+
+ if (key == lastKey)
+ painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));
+
+ painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.width(QChar(key))/2,
+ row*squareSize + 4 + fontMetrics.ascent(),
+ QString(QChar(key)));
+ }
+ }
+}
+//! [10]
diff --git a/examples/widgets/charactermap/characterwidget.h b/examples/widgets/charactermap/characterwidget.h
new file mode 100644
index 0000000000..2ccb0aefed
--- /dev/null
+++ b/examples/widgets/charactermap/characterwidget.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CHARACTERWIDGET_H
+#define CHARACTERWIDGET_H
+
+#include <QFont>
+#include <QPoint>
+#include <QSize>
+#include <QString>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QMouseEvent;
+class QPaintEvent;
+QT_END_NAMESPACE
+
+//! [0]
+class CharacterWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CharacterWidget(QWidget *parent = 0);
+ QSize sizeHint() const;
+
+public slots:
+ void updateFont(const QFont &font);
+ void updateSize(const QString &fontSize);
+ void updateStyle(const QString &fontStyle);
+ void updateFontMerging(bool enable);
+
+signals:
+ void characterSelected(const QString &character);
+
+protected:
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+
+private:
+ QFont displayFont;
+ int columns;
+ int lastKey;
+ int squareSize;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/charactermap/main.cpp b/examples/widgets/charactermap/main.cpp
new file mode 100644
index 0000000000..01c8adae53
--- /dev/null
+++ b/examples/widgets/charactermap/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/charactermap/mainwindow.cpp
new file mode 100644
index 0000000000..bdff127423
--- /dev/null
+++ b/examples/widgets/charactermap/mainwindow.cpp
@@ -0,0 +1,195 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "characterwidget.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QWidget *centralWidget = new QWidget;
+
+ QLabel *fontLabel = new QLabel(tr("Font:"));
+ fontCombo = new QFontComboBox;
+ QLabel *sizeLabel = new QLabel(tr("Size:"));
+ sizeCombo = new QComboBox;
+ QLabel *styleLabel = new QLabel(tr("Style:"));
+ styleCombo = new QComboBox;
+ QLabel *fontMergingLabel = new QLabel(tr("Automatic Font Merging:"));
+ fontMerging = new QCheckBox;
+ fontMerging->setChecked(true);
+
+ scrollArea = new QScrollArea;
+ characterWidget = new CharacterWidget;
+ scrollArea->setWidget(characterWidget);
+//! [0]
+
+//! [1]
+ findStyles(fontCombo->currentFont());
+//! [1]
+ findSizes(fontCombo->currentFont());
+
+//! [2]
+ lineEdit = new QLineEdit;
+ QPushButton *clipboardButton = new QPushButton(tr("&To clipboard"));
+//! [2]
+
+//! [3]
+ clipboard = QApplication::clipboard();
+//! [3]
+
+//! [4]
+ connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
+ this, SLOT(findStyles(QFont)));
+ connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
+ this, SLOT(findSizes(QFont)));
+ connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
+ characterWidget, SLOT(updateFont(QFont)));
+ connect(sizeCombo, SIGNAL(currentIndexChanged(QString)),
+ characterWidget, SLOT(updateSize(QString)));
+ connect(styleCombo, SIGNAL(currentIndexChanged(QString)),
+ characterWidget, SLOT(updateStyle(QString)));
+//! [4] //! [5]
+ connect(characterWidget, SIGNAL(characterSelected(QString)),
+ this, SLOT(insertCharacter(QString)));
+ connect(clipboardButton, SIGNAL(clicked()), this, SLOT(updateClipboard()));
+//! [5]
+ connect(fontMerging, SIGNAL(toggled(bool)), characterWidget, SLOT(updateFontMerging(bool)));
+
+//! [6]
+ QHBoxLayout *controlsLayout = new QHBoxLayout;
+ controlsLayout->addWidget(fontLabel);
+ controlsLayout->addWidget(fontCombo, 1);
+ controlsLayout->addWidget(sizeLabel);
+ controlsLayout->addWidget(sizeCombo, 1);
+ controlsLayout->addWidget(styleLabel);
+ controlsLayout->addWidget(styleCombo, 1);
+ controlsLayout->addWidget(fontMergingLabel);
+ controlsLayout->addWidget(fontMerging, 1);
+ controlsLayout->addStretch(1);
+
+ QHBoxLayout *lineLayout = new QHBoxLayout;
+ lineLayout->addWidget(lineEdit, 1);
+ lineLayout->addSpacing(12);
+ lineLayout->addWidget(clipboardButton);
+
+ QVBoxLayout *centralLayout = new QVBoxLayout;
+ centralLayout->addLayout(controlsLayout);
+ centralLayout->addWidget(scrollArea, 1);
+ centralLayout->addSpacing(4);
+ centralLayout->addLayout(lineLayout);
+ centralWidget->setLayout(centralLayout);
+
+ setCentralWidget(centralWidget);
+ setWindowTitle(tr("Character Map"));
+}
+//! [6]
+
+//! [7]
+void MainWindow::findStyles(const QFont &font)
+{
+ QFontDatabase fontDatabase;
+ QString currentItem = styleCombo->currentText();
+ styleCombo->clear();
+//! [7]
+
+//! [8]
+ QString style;
+ foreach (style, fontDatabase.styles(font.family()))
+ styleCombo->addItem(style);
+
+ int styleIndex = styleCombo->findText(currentItem);
+
+ if (styleIndex == -1)
+ styleCombo->setCurrentIndex(0);
+ else
+ styleCombo->setCurrentIndex(styleIndex);
+}
+//! [8]
+
+void MainWindow::findSizes(const QFont &font)
+{
+ QFontDatabase fontDatabase;
+ QString currentSize = sizeCombo->currentText();
+ sizeCombo->blockSignals(true);
+ sizeCombo->clear();
+
+ int size;
+ if(fontDatabase.isSmoothlyScalable(font.family(), fontDatabase.styleString(font))) {
+ foreach(size, QFontDatabase::standardSizes()) {
+ sizeCombo->addItem(QVariant(size).toString());
+ sizeCombo->setEditable(true);
+ }
+
+ } else {
+ foreach(size, fontDatabase.smoothSizes(font.family(), fontDatabase.styleString(font))) {
+ sizeCombo->addItem(QVariant(size).toString());
+ sizeCombo->setEditable(false);
+ }
+ }
+
+ sizeCombo->blockSignals(false);
+
+ int sizeIndex = sizeCombo->findText(currentSize);
+
+ if(sizeIndex == -1)
+ sizeCombo->setCurrentIndex(qMax(0, sizeCombo->count() / 3));
+ else
+ sizeCombo->setCurrentIndex(sizeIndex);
+}
+
+//! [9]
+void MainWindow::insertCharacter(const QString &character)
+{
+ lineEdit->insert(character);
+}
+//! [9]
+
+//! [10]
+void MainWindow::updateClipboard()
+{
+//! [11]
+ clipboard->setText(lineEdit->text(), QClipboard::Clipboard);
+//! [11]
+ clipboard->setText(lineEdit->text(), QClipboard::Selection);
+}
+//! [10]
diff --git a/examples/widgets/charactermap/mainwindow.h b/examples/widgets/charactermap/mainwindow.h
new file mode 100644
index 0000000000..9c4e4f50ab
--- /dev/null
+++ b/examples/widgets/charactermap/mainwindow.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+class QClipboard;
+class QComboBox;
+class QFontComboBox;
+class QLineEdit;
+class QScrollArea;
+class QCheckBox;
+QT_END_NAMESPACE
+class CharacterWidget;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void findStyles(const QFont &font);
+ void findSizes(const QFont &font);
+ void insertCharacter(const QString &character);
+ void updateClipboard();
+
+private:
+ CharacterWidget *characterWidget;
+ QClipboard *clipboard;
+ QComboBox *styleCombo;
+ QComboBox *sizeCombo;
+ QFontComboBox *fontCombo;
+ QLineEdit *lineEdit;
+ QScrollArea *scrollArea;
+ QCheckBox *fontMerging;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/codeeditor/codeeditor.cpp b/examples/widgets/codeeditor/codeeditor.cpp
new file mode 100644
index 0000000000..c7d1405a0e
--- /dev/null
+++ b/examples/widgets/codeeditor/codeeditor.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "codeeditor.h"
+
+//![constructor]
+
+CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
+{
+ lineNumberArea = new LineNumberArea(this);
+
+ connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
+ connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
+ connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
+
+ updateLineNumberAreaWidth(0);
+ highlightCurrentLine();
+}
+
+//![constructor]
+
+//![extraAreaWidth]
+
+int CodeEditor::lineNumberAreaWidth()
+{
+ int digits = 1;
+ int max = qMax(1, blockCount());
+ while (max >= 10) {
+ max /= 10;
+ ++digits;
+ }
+
+ int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
+
+ return space;
+}
+
+//![extraAreaWidth]
+
+//![slotUpdateExtraAreaWidth]
+
+void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
+{
+ setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
+}
+
+//![slotUpdateExtraAreaWidth]
+
+//![slotUpdateRequest]
+
+void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
+{
+ if (dy)
+ lineNumberArea->scroll(0, dy);
+ else
+ lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
+
+ if (rect.contains(viewport()->rect()))
+ updateLineNumberAreaWidth(0);
+}
+
+//![slotUpdateRequest]
+
+//![resizeEvent]
+
+void CodeEditor::resizeEvent(QResizeEvent *e)
+{
+ QPlainTextEdit::resizeEvent(e);
+
+ QRect cr = contentsRect();
+ lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
+}
+
+//![resizeEvent]
+
+//![cursorPositionChanged]
+
+void CodeEditor::highlightCurrentLine()
+{
+ QList<QTextEdit::ExtraSelection> extraSelections;
+
+ if (!isReadOnly()) {
+ QTextEdit::ExtraSelection selection;
+
+ QColor lineColor = QColor(Qt::yellow).lighter(160);
+
+ selection.format.setBackground(lineColor);
+ selection.format.setProperty(QTextFormat::FullWidthSelection, true);
+ selection.cursor = textCursor();
+ selection.cursor.clearSelection();
+ extraSelections.append(selection);
+ }
+
+ setExtraSelections(extraSelections);
+}
+
+//![cursorPositionChanged]
+
+//![extraAreaPaintEvent_0]
+
+void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
+{
+ QPainter painter(lineNumberArea);
+ painter.fillRect(event->rect(), Qt::lightGray);
+
+//![extraAreaPaintEvent_0]
+
+//![extraAreaPaintEvent_1]
+ QTextBlock block = firstVisibleBlock();
+ int blockNumber = block.blockNumber();
+ int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
+ int bottom = top + (int) blockBoundingRect(block).height();
+//![extraAreaPaintEvent_1]
+
+//![extraAreaPaintEvent_2]
+ while (block.isValid() && top <= event->rect().bottom()) {
+ if (block.isVisible() && bottom >= event->rect().top()) {
+ QString number = QString::number(blockNumber + 1);
+ painter.setPen(Qt::black);
+ painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
+ Qt::AlignRight, number);
+ }
+
+ block = block.next();
+ top = bottom;
+ bottom = top + (int) blockBoundingRect(block).height();
+ ++blockNumber;
+ }
+}
+//![extraAreaPaintEvent_2]
+
diff --git a/examples/widgets/codeeditor/codeeditor.h b/examples/widgets/codeeditor/codeeditor.h
new file mode 100644
index 0000000000..84ce5c698a
--- /dev/null
+++ b/examples/widgets/codeeditor/codeeditor.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CODEEDITOR_H
+#define CODEEDITOR_H
+
+#include <QPlainTextEdit>
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+class QResizeEvent;
+class QSize;
+class QWidget;
+QT_END_NAMESPACE
+
+class LineNumberArea;
+
+//![codeeditordefinition]
+
+class CodeEditor : public QPlainTextEdit
+{
+ Q_OBJECT
+
+public:
+ CodeEditor(QWidget *parent = 0);
+
+ void lineNumberAreaPaintEvent(QPaintEvent *event);
+ int lineNumberAreaWidth();
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private slots:
+ void updateLineNumberAreaWidth(int newBlockCount);
+ void highlightCurrentLine();
+ void updateLineNumberArea(const QRect &, int);
+
+private:
+ QWidget *lineNumberArea;
+};
+
+//![codeeditordefinition]
+//![extraarea]
+
+class LineNumberArea : public QWidget
+{
+public:
+ LineNumberArea(CodeEditor *editor) : QWidget(editor) {
+ codeEditor = editor;
+ }
+
+ QSize sizeHint() const {
+ return QSize(codeEditor->lineNumberAreaWidth(), 0);
+ }
+
+protected:
+ void paintEvent(QPaintEvent *event) {
+ codeEditor->lineNumberAreaPaintEvent(event);
+ }
+
+private:
+ CodeEditor *codeEditor;
+};
+
+//![extraarea]
+
+#endif
diff --git a/examples/widgets/codeeditor/codeeditor.pro b/examples/widgets/codeeditor/codeeditor.pro
new file mode 100644
index 0000000000..2e15d86a8d
--- /dev/null
+++ b/examples/widgets/codeeditor/codeeditor.pro
@@ -0,0 +1,9 @@
+HEADERS = codeeditor.h
+SOURCES = main.cpp \
+ codeeditor.cpp
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/codeeditor
+sources.files = $$SOURCES $$HEADERS *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/codeeditor
+INSTALLS += target sources
+
diff --git a/examples/widgets/codeeditor/main.cpp b/examples/widgets/codeeditor/main.cpp
new file mode 100644
index 0000000000..a2a81a1a85
--- /dev/null
+++ b/examples/widgets/codeeditor/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "codeeditor.h"
+
+int main(int argv, char **args)
+{
+ QApplication app(argv, args);
+
+ CodeEditor editor;
+ editor.setWindowTitle(QObject::tr("Code Editor Example"));
+ editor.show();
+
+ return app.exec();
+}
+
diff --git a/examples/widgets/digitalclock/digitalclock.cpp b/examples/widgets/digitalclock/digitalclock.cpp
new file mode 100644
index 0000000000..7d38ccd15f
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "digitalclock.h"
+
+//! [0]
+DigitalClock::DigitalClock(QWidget *parent)
+ : QLCDNumber(parent)
+{
+ setSegmentStyle(Filled);
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
+ timer->start(1000);
+
+ showTime();
+
+ setWindowTitle(tr("Digital Clock"));
+ resize(150, 60);
+}
+//! [0]
+
+//! [1]
+void DigitalClock::showTime()
+//! [1] //! [2]
+{
+ QTime time = QTime::currentTime();
+ QString text = time.toString("hh:mm");
+ if ((time.second() % 2) == 0)
+ text[2] = ' ';
+ display(text);
+}
+//! [2]
diff --git a/examples/widgets/digitalclock/digitalclock.h b/examples/widgets/digitalclock/digitalclock.h
new file mode 100644
index 0000000000..3902b14869
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIGITALCLOCK_H
+#define DIGITALCLOCK_H
+
+#include <QLCDNumber>
+
+//! [0]
+class DigitalClock : public QLCDNumber
+{
+ Q_OBJECT
+
+public:
+ DigitalClock(QWidget *parent = 0);
+
+private slots:
+ void showTime();
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/digitalclock/digitalclock.pro b/examples/widgets/digitalclock/digitalclock.pro
new file mode 100644
index 0000000000..2d0e7ce709
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.pro
@@ -0,0 +1,11 @@
+HEADERS = digitalclock.h
+SOURCES = digitalclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/digitalclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS digitalclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/digitalclock
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/digitalclock/main.cpp b/examples/widgets/digitalclock/main.cpp
new file mode 100644
index 0000000000..c43162bade
--- /dev/null
+++ b/examples/widgets/digitalclock/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "digitalclock.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ DigitalClock clock;
+ clock.show();
+ return app.exec();
+}
diff --git a/examples/widgets/groupbox/groupbox.pro b/examples/widgets/groupbox/groupbox.pro
new file mode 100644
index 0000000000..817ff26c41
--- /dev/null
+++ b/examples/widgets/groupbox/groupbox.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h
+SOURCES = window.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/groupbox
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS groupbox.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/groupbox
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/groupbox/main.cpp b/examples/widgets/groupbox/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/widgets/groupbox/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/groupbox/window.cpp
new file mode 100644
index 0000000000..89531df9fd
--- /dev/null
+++ b/examples/widgets/groupbox/window.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window(QWidget *parent)
+ : QWidget(parent)
+{
+ QGridLayout *grid = new QGridLayout;
+ grid->addWidget(createFirstExclusiveGroup(), 0, 0);
+ grid->addWidget(createSecondExclusiveGroup(), 1, 0);
+ grid->addWidget(createNonExclusiveGroup(), 0, 1);
+ grid->addWidget(createPushButtonGroup(), 1, 1);
+ setLayout(grid);
+
+ setWindowTitle(tr("Group Boxes"));
+ resize(480, 320);
+}
+//! [0]
+
+//! [1]
+QGroupBox *Window::createFirstExclusiveGroup()
+{
+//! [2]
+ QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
+
+ QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
+ QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
+ QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
+
+ radio1->setChecked(true);
+//! [1] //! [3]
+
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(radio1);
+ vbox->addWidget(radio2);
+ vbox->addWidget(radio3);
+ vbox->addStretch(1);
+ groupBox->setLayout(vbox);
+//! [2]
+
+ return groupBox;
+}
+//! [3]
+
+//! [4]
+QGroupBox *Window::createSecondExclusiveGroup()
+{
+ QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
+ groupBox->setCheckable(true);
+ groupBox->setChecked(false);
+//! [4]
+
+//! [5]
+ QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1"));
+ QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2"));
+ QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3"));
+ radio1->setChecked(true);
+ QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox"));
+ checkBox->setChecked(true);
+//! [5]
+
+//! [6]
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(radio1);
+ vbox->addWidget(radio2);
+ vbox->addWidget(radio3);
+ vbox->addWidget(checkBox);
+ vbox->addStretch(1);
+ groupBox->setLayout(vbox);
+
+ return groupBox;
+}
+//! [6]
+
+//! [7]
+QGroupBox *Window::createNonExclusiveGroup()
+{
+ QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes"));
+ groupBox->setFlat(true);
+//! [7]
+
+//! [8]
+ QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
+ QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
+ checkBox2->setChecked(true);
+ QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
+ tristateBox->setTristate(true);
+//! [8]
+ tristateBox->setCheckState(Qt::PartiallyChecked);
+
+//! [9]
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(checkBox1);
+ vbox->addWidget(checkBox2);
+ vbox->addWidget(tristateBox);
+ vbox->addStretch(1);
+ groupBox->setLayout(vbox);
+
+ return groupBox;
+}
+//! [9]
+
+//! [10]
+QGroupBox *Window::createPushButtonGroup()
+{
+ QGroupBox *groupBox = new QGroupBox(tr("&Push Buttons"));
+ groupBox->setCheckable(true);
+ groupBox->setChecked(true);
+//! [10]
+
+//! [11]
+ QPushButton *pushButton = new QPushButton(tr("&Normal Button"));
+ QPushButton *toggleButton = new QPushButton(tr("&Toggle Button"));
+ toggleButton->setCheckable(true);
+ toggleButton->setChecked(true);
+ QPushButton *flatButton = new QPushButton(tr("&Flat Button"));
+ flatButton->setFlat(true);
+//! [11]
+
+//! [12]
+ QPushButton *popupButton = new QPushButton(tr("Pop&up Button"));
+ QMenu *menu = new QMenu(this);
+ menu->addAction(tr("&First Item"));
+ menu->addAction(tr("&Second Item"));
+ menu->addAction(tr("&Third Item"));
+ menu->addAction(tr("F&ourth Item"));
+ popupButton->setMenu(menu);
+//! [12]
+
+ QAction *newAction = menu->addAction(tr("Submenu"));
+ QMenu *subMenu = new QMenu(tr("Popup Submenu"));
+ subMenu->addAction(tr("Item 1"));
+ subMenu->addAction(tr("Item 2"));
+ subMenu->addAction(tr("Item 3"));
+ newAction->setMenu(subMenu);
+
+//! [13]
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(pushButton);
+ vbox->addWidget(toggleButton);
+ vbox->addWidget(flatButton);
+ vbox->addWidget(popupButton);
+ vbox->addStretch(1);
+ groupBox->setLayout(vbox);
+
+ return groupBox;
+}
+//! [13]
diff --git a/examples/widgets/groupbox/window.h b/examples/widgets/groupbox/window.h
new file mode 100644
index 0000000000..1029d534c8
--- /dev/null
+++ b/examples/widgets/groupbox/window.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QGroupBox;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = 0);
+
+private:
+ QGroupBox *createFirstExclusiveGroup();
+ QGroupBox *createSecondExclusiveGroup();
+ QGroupBox *createNonExclusiveGroup();
+ QGroupBox *createPushButtonGroup();
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/icons/iconpreviewarea.cpp b/examples/widgets/icons/iconpreviewarea.cpp
new file mode 100644
index 0000000000..3f3de3d135
--- /dev/null
+++ b/examples/widgets/icons/iconpreviewarea.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "iconpreviewarea.h"
+
+//! [0]
+IconPreviewArea::IconPreviewArea(QWidget *parent)
+ : QWidget(parent)
+{
+ QGridLayout *mainLayout = new QGridLayout;
+ setLayout(mainLayout);
+
+ stateLabels[0] = createHeaderLabel(tr("Off"));
+ stateLabels[1] = createHeaderLabel(tr("On"));
+ Q_ASSERT(NumStates == 2);
+
+ modeLabels[0] = createHeaderLabel(tr("Normal"));
+ modeLabels[1] = createHeaderLabel(tr("Active"));
+ modeLabels[2] = createHeaderLabel(tr("Disabled"));
+ modeLabels[3] = createHeaderLabel(tr("Selected"));
+ Q_ASSERT(NumModes == 4);
+
+ for (int j = 0; j < NumStates; ++j)
+ mainLayout->addWidget(stateLabels[j], j + 1, 0);
+
+ for (int i = 0; i < NumModes; ++i) {
+ mainLayout->addWidget(modeLabels[i], 0, i + 1);
+
+ for (int j = 0; j < NumStates; ++j) {
+ pixmapLabels[i][j] = createPixmapLabel();
+ mainLayout->addWidget(pixmapLabels[i][j], j + 1, i + 1);
+ }
+ }
+}
+//! [0]
+
+//! [1]
+void IconPreviewArea::setIcon(const QIcon &icon)
+{
+ this->icon = icon;
+ updatePixmapLabels();
+}
+//! [1]
+
+//! [2]
+void IconPreviewArea::setSize(const QSize &size)
+{
+ if (size != this->size) {
+ this->size = size;
+ updatePixmapLabels();
+ }
+}
+//! [2]
+
+//! [3]
+QLabel *IconPreviewArea::createHeaderLabel(const QString &text)
+{
+ QLabel *label = new QLabel(tr("<b>%1</b>").arg(text));
+ label->setAlignment(Qt::AlignCenter);
+ return label;
+}
+//! [3]
+
+//! [4]
+QLabel *IconPreviewArea::createPixmapLabel()
+{
+ QLabel *label = new QLabel;
+ label->setEnabled(false);
+ label->setAlignment(Qt::AlignCenter);
+ label->setFrameShape(QFrame::Box);
+ label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ label->setBackgroundRole(QPalette::Base);
+ label->setAutoFillBackground(true);
+ label->setMinimumSize(132, 132);
+ return label;
+}
+//! [4]
+
+//! [5]
+void IconPreviewArea::updatePixmapLabels()
+{
+ for (int i = 0; i < NumModes; ++i) {
+ QIcon::Mode mode;
+ if (i == 0) {
+ mode = QIcon::Normal;
+ } else if (i == 1) {
+ mode = QIcon::Active;
+ } else if (i == 2) {
+ mode = QIcon::Disabled;
+ } else {
+ mode = QIcon::Selected;
+ }
+
+ for (int j = 0; j < NumStates; ++j) {
+ QIcon::State state = (j == 0) ? QIcon::Off : QIcon::On;
+ QPixmap pixmap = icon.pixmap(size, mode, state);
+ pixmapLabels[i][j]->setPixmap(pixmap);
+ pixmapLabels[i][j]->setEnabled(!pixmap.isNull());
+ }
+ }
+}
+//! [5]
diff --git a/examples/widgets/icons/iconpreviewarea.h b/examples/widgets/icons/iconpreviewarea.h
new file mode 100644
index 0000000000..def2b3b1de
--- /dev/null
+++ b/examples/widgets/icons/iconpreviewarea.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ICONPREVIEWAREA_H
+#define ICONPREVIEWAREA_H
+
+#include <QIcon>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+
+//! [0]
+class IconPreviewArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ IconPreviewArea(QWidget *parent = 0);
+
+ void setIcon(const QIcon &icon);
+ void setSize(const QSize &size);
+
+private:
+ QLabel *createHeaderLabel(const QString &text);
+ QLabel *createPixmapLabel();
+ void updatePixmapLabels();
+
+ enum { NumModes = 4, NumStates = 2 };
+
+ QIcon icon;
+ QSize size;
+ QLabel *stateLabels[NumStates];
+ QLabel *modeLabels[NumModes];
+ QLabel *pixmapLabels[NumModes][NumStates];
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/icons/icons.pro b/examples/widgets/icons/icons.pro
new file mode 100644
index 0000000000..deeb5881ba
--- /dev/null
+++ b/examples/widgets/icons/icons.pro
@@ -0,0 +1,27 @@
+HEADERS = iconpreviewarea.h \
+ iconsizespinbox.h \
+ imagedelegate.h \
+ mainwindow.h
+SOURCES = iconpreviewarea.cpp \
+ iconsizespinbox.cpp \
+ imagedelegate.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/icons
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS icons.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/icons
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: {
+ imageFiles.files = images/*
+ wincewm*: {
+ imageFiles.path = "/My Documents/My Pictures"
+ } else {
+ imageFiles.path = images
+ }
+ DEPLOYMENT += imageFiles
+}
diff --git a/examples/widgets/icons/iconsizespinbox.cpp b/examples/widgets/icons/iconsizespinbox.cpp
new file mode 100644
index 0000000000..fd3722af8f
--- /dev/null
+++ b/examples/widgets/icons/iconsizespinbox.cpp
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "iconsizespinbox.h"
+
+//! [0]
+IconSizeSpinBox::IconSizeSpinBox(QWidget *parent)
+ : QSpinBox(parent)
+{
+}
+//! [0]
+
+//! [1]
+int IconSizeSpinBox::valueFromText(const QString &text) const
+{
+ QRegExp regExp(tr("(\\d+)(\\s*[xx]\\s*\\d+)?"));
+
+ if (regExp.exactMatch(text)) {
+ return regExp.cap(1).toInt();
+ } else {
+ return 0;
+ }
+}
+//! [1]
+
+//! [2]
+QString IconSizeSpinBox::textFromValue(int value) const
+{
+ return tr("%1 x %1").arg(value);
+}
+//! [2]
diff --git a/examples/widgets/icons/iconsizespinbox.h b/examples/widgets/icons/iconsizespinbox.h
new file mode 100644
index 0000000000..da6b9d3c7b
--- /dev/null
+++ b/examples/widgets/icons/iconsizespinbox.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ICONSIZESPINBOX_H
+#define ICONSIZESPINBOX_H
+
+#include <QSpinBox>
+
+//! [0]
+class IconSizeSpinBox : public QSpinBox
+{
+ Q_OBJECT
+
+public:
+ IconSizeSpinBox(QWidget *parent = 0);
+
+ int valueFromText(const QString &text) const;
+ QString textFromValue(int value) const;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/icons/imagedelegate.cpp b/examples/widgets/icons/imagedelegate.cpp
new file mode 100644
index 0000000000..93018eb49b
--- /dev/null
+++ b/examples/widgets/icons/imagedelegate.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "imagedelegate.h"
+
+//! [0]
+ImageDelegate::ImageDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+}
+//! [0]
+
+//! [1]
+QWidget *ImageDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem & /* option */,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = new QComboBox(parent);
+ if (index.column() == 1) {
+ comboBox->addItem(tr("Normal"));
+ comboBox->addItem(tr("Active"));
+ comboBox->addItem(tr("Disabled"));
+ comboBox->addItem(tr("Selected"));
+ } else if (index.column() == 2) {
+ comboBox->addItem(tr("Off"));
+ comboBox->addItem(tr("On"));
+ }
+
+ connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData()));
+
+ return comboBox;
+}
+//! [1]
+
+//! [2]
+void ImageDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
+ if (!comboBox)
+ return;
+
+ int pos = comboBox->findText(index.model()->data(index).toString(),
+ Qt::MatchExactly);
+ comboBox->setCurrentIndex(pos);
+}
+//! [2]
+
+//! [3]
+void ImageDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
+ if (!comboBox)
+ return;
+
+ model->setData(index, comboBox->currentText());
+}
+//! [3]
+
+//! [4]
+void ImageDelegate::emitCommitData()
+{
+ emit commitData(qobject_cast<QWidget *>(sender()));
+}
+//! [4]
diff --git a/examples/widgets/icons/imagedelegate.h b/examples/widgets/icons/imagedelegate.h
new file mode 100644
index 0000000000..979e12253c
--- /dev/null
+++ b/examples/widgets/icons/imagedelegate.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGEDELEGATE_H
+#define IMAGEDELEGATE_H
+
+#include <QItemDelegate>
+
+//! [0]
+class ImageDelegate : public QItemDelegate
+{
+ Q_OBJECT
+
+public:
+ ImageDelegate(QObject *parent = 0);
+//! [0]
+
+//! [1]
+ 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;
+
+//! [1] //! [2]
+private slots:
+ void emitCommitData();
+};
+//! [2]
+
+#endif
diff --git a/examples/widgets/icons/images/designer.png b/examples/widgets/icons/images/designer.png
new file mode 100644
index 0000000000..0988fcee3f
--- /dev/null
+++ b/examples/widgets/icons/images/designer.png
Binary files differ
diff --git a/examples/widgets/icons/images/find_disabled.png b/examples/widgets/icons/images/find_disabled.png
new file mode 100644
index 0000000000..e85e33fe05
--- /dev/null
+++ b/examples/widgets/icons/images/find_disabled.png
Binary files differ
diff --git a/examples/widgets/icons/images/find_normal.png b/examples/widgets/icons/images/find_normal.png
new file mode 100644
index 0000000000..728c27f905
--- /dev/null
+++ b/examples/widgets/icons/images/find_normal.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_128x128.png b/examples/widgets/icons/images/monkey_off_128x128.png
new file mode 100644
index 0000000000..f878267287
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_off_128x128.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_16x16.png b/examples/widgets/icons/images/monkey_off_16x16.png
new file mode 100644
index 0000000000..0ac57d7d4f
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_off_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_32x32.png b/examples/widgets/icons/images/monkey_off_32x32.png
new file mode 100644
index 0000000000..1f7fab694c
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_off_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_off_64x64.png b/examples/widgets/icons/images/monkey_off_64x64.png
new file mode 100644
index 0000000000..47d8f6de35
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_off_64x64.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_128x128.png b/examples/widgets/icons/images/monkey_on_128x128.png
new file mode 100644
index 0000000000..8e1c7468bf
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_on_128x128.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_16x16.png b/examples/widgets/icons/images/monkey_on_16x16.png
new file mode 100644
index 0000000000..082e8527f1
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_on_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_32x32.png b/examples/widgets/icons/images/monkey_on_32x32.png
new file mode 100644
index 0000000000..bf9acc6cae
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_on_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/monkey_on_64x64.png b/examples/widgets/icons/images/monkey_on_64x64.png
new file mode 100644
index 0000000000..990f604d98
--- /dev/null
+++ b/examples/widgets/icons/images/monkey_on_64x64.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/icons/images/qt_extended_16x16.png
new file mode 100644
index 0000000000..95d3bae838
--- /dev/null
+++ b/examples/widgets/icons/images/qt_extended_16x16.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/icons/images/qt_extended_32x32.png
new file mode 100644
index 0000000000..7b7a790c12
--- /dev/null
+++ b/examples/widgets/icons/images/qt_extended_32x32.png
Binary files differ
diff --git a/examples/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/icons/images/qt_extended_48x48.png
new file mode 100644
index 0000000000..8434dc26db
--- /dev/null
+++ b/examples/widgets/icons/images/qt_extended_48x48.png
Binary files differ
diff --git a/examples/widgets/icons/main.cpp b/examples/widgets/icons/main.cpp
new file mode 100644
index 0000000000..923c1f8514
--- /dev/null
+++ b/examples/widgets/icons/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ return app.exec();
+}
diff --git a/examples/widgets/icons/mainwindow.cpp b/examples/widgets/icons/mainwindow.cpp
new file mode 100644
index 0000000000..6dda3c16db
--- /dev/null
+++ b/examples/widgets/icons/mainwindow.cpp
@@ -0,0 +1,442 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "iconpreviewarea.h"
+#include "iconsizespinbox.h"
+#include "imagedelegate.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ centralWidget = new QWidget;
+ setCentralWidget(centralWidget);
+
+ createPreviewGroupBox();
+ createImagesGroupBox();
+ createIconSizeGroupBox();
+
+ createActions();
+ createMenus();
+ createContextMenu();
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(previewGroupBox, 0, 0, 1, 2);
+ mainLayout->addWidget(imagesGroupBox, 1, 0);
+ mainLayout->addWidget(iconSizeGroupBox, 1, 1);
+ centralWidget->setLayout(mainLayout);
+
+ setWindowTitle(tr("Icons"));
+ checkCurrentStyle();
+ otherRadioButton->click();
+
+ resize(minimumSizeHint());
+}
+//! [0]
+
+//! [1]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Icons"),
+ tr("The <b>Icons</b> example illustrates how Qt renders an icon in "
+ "different modes (active, normal, disabled, and selected) and "
+ "states (on and off) based on a set of images."));
+}
+//! [1]
+
+//! [2]
+void MainWindow::changeStyle(bool checked)
+{
+ if (!checked)
+ return;
+
+ QAction *action = qobject_cast<QAction *>(sender());
+//! [2] //! [3]
+ QStyle *style = QStyleFactory::create(action->data().toString());
+//! [3] //! [4]
+ Q_ASSERT(style);
+ QApplication::setStyle(style);
+
+ smallRadioButton->setText(tr("Small (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_SmallIconSize)));
+ largeRadioButton->setText(tr("Large (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_LargeIconSize)));
+ toolBarRadioButton->setText(tr("Toolbars (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_ToolBarIconSize)));
+ listViewRadioButton->setText(tr("List views (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_ListViewIconSize)));
+ iconViewRadioButton->setText(tr("Icon views (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_IconViewIconSize)));
+ tabBarRadioButton->setText(tr("Tab bars (%1 x %1)")
+ .arg(style->pixelMetric(QStyle::PM_TabBarIconSize)));
+
+ changeSize();
+}
+//! [4]
+
+//! [5]
+void MainWindow::changeSize(bool checked)
+{
+ if (!checked)
+ return;
+
+ int extent;
+
+ if (otherRadioButton->isChecked()) {
+ extent = otherSpinBox->value();
+ } else {
+ QStyle::PixelMetric metric;
+
+ if (smallRadioButton->isChecked()) {
+ metric = QStyle::PM_SmallIconSize;
+ } else if (largeRadioButton->isChecked()) {
+ metric = QStyle::PM_LargeIconSize;
+ } else if (toolBarRadioButton->isChecked()) {
+ metric = QStyle::PM_ToolBarIconSize;
+ } else if (listViewRadioButton->isChecked()) {
+ metric = QStyle::PM_ListViewIconSize;
+ } else if (iconViewRadioButton->isChecked()) {
+ metric = QStyle::PM_IconViewIconSize;
+ } else {
+ metric = QStyle::PM_TabBarIconSize;
+ }
+ extent = QApplication::style()->pixelMetric(metric);
+ }
+ previewArea->setSize(QSize(extent, extent));
+ otherSpinBox->setEnabled(otherRadioButton->isChecked());
+}
+//! [5]
+
+//! [6]
+void MainWindow::changeIcon()
+{
+ QIcon icon;
+
+ for (int row = 0; row < imagesTable->rowCount(); ++row) {
+ QTableWidgetItem *item0 = imagesTable->item(row, 0);
+ QTableWidgetItem *item1 = imagesTable->item(row, 1);
+ QTableWidgetItem *item2 = imagesTable->item(row, 2);
+
+ if (item0->checkState() == Qt::Checked) {
+ QIcon::Mode mode;
+ if (item1->text() == tr("Normal")) {
+ mode = QIcon::Normal;
+ } else if (item1->text() == tr("Active")) {
+ mode = QIcon::Active;
+ } else if (item1->text() == tr("Disabled")) {
+ mode = QIcon::Disabled;
+ } else {
+ mode = QIcon::Selected;
+ }
+
+ QIcon::State state;
+ if (item2->text() == tr("On")) {
+ state = QIcon::On;
+ } else {
+ state = QIcon::Off;
+//! [6] //! [7]
+ }
+//! [7]
+
+//! [8]
+ QString fileName = item0->data(Qt::UserRole).toString();
+ QImage image(fileName);
+ if (!image.isNull())
+ icon.addPixmap(QPixmap::fromImage(image), mode, state);
+//! [8] //! [9]
+ }
+//! [9] //! [10]
+ }
+//! [10]
+
+//! [11]
+ previewArea->setIcon(icon);
+}
+//! [11]
+
+//! [12]
+void MainWindow::addImages()
+{
+ QStringList fileNames = QFileDialog::getOpenFileNames(this,
+ tr("Open Images"), "",
+ tr("Images (*.png *.xpm *.jpg);;"
+ "All Files (*)"));
+ if (!fileNames.isEmpty()) {
+ foreach (QString fileName, fileNames) {
+ int row = imagesTable->rowCount();
+ imagesTable->setRowCount(row + 1);
+//! [12]
+
+//! [13]
+ QString imageName = QFileInfo(fileName).baseName();
+//! [13] //! [14]
+ QTableWidgetItem *item0 = new QTableWidgetItem(imageName);
+ item0->setData(Qt::UserRole, fileName);
+ item0->setFlags(item0->flags() & ~Qt::ItemIsEditable);
+//! [14]
+
+//! [15]
+ QTableWidgetItem *item1 = new QTableWidgetItem(tr("Normal"));
+//! [15] //! [16]
+ QTableWidgetItem *item2 = new QTableWidgetItem(tr("Off"));
+
+ if (guessModeStateAct->isChecked()) {
+ if (fileName.contains("_act")) {
+ item1->setText(tr("Active"));
+ } else if (fileName.contains("_dis")) {
+ item1->setText(tr("Disabled"));
+ } else if (fileName.contains("_sel")) {
+ item1->setText(tr("Selected"));
+ }
+
+ if (fileName.contains("_on"))
+ item2->setText(tr("On"));
+//! [16] //! [17]
+ }
+//! [17]
+
+//! [18]
+ imagesTable->setItem(row, 0, item0);
+//! [18] //! [19]
+ imagesTable->setItem(row, 1, item1);
+ imagesTable->setItem(row, 2, item2);
+ imagesTable->openPersistentEditor(item1);
+ imagesTable->openPersistentEditor(item2);
+
+ item0->setCheckState(Qt::Checked);
+ }
+ }
+}
+//! [19]
+
+//! [20]
+void MainWindow::removeAllImages()
+{
+ imagesTable->setRowCount(0);
+ changeIcon();
+}
+//! [20]
+
+void MainWindow::createPreviewGroupBox()
+{
+ previewGroupBox = new QGroupBox(tr("Preview"));
+
+ previewArea = new IconPreviewArea;
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(previewArea);
+ previewGroupBox->setLayout(layout);
+}
+
+//! [21]
+void MainWindow::createImagesGroupBox()
+{
+ imagesGroupBox = new QGroupBox(tr("Images"));
+
+ imagesTable = new QTableWidget;
+ imagesTable->setSelectionMode(QAbstractItemView::NoSelection);
+ imagesTable->setItemDelegate(new ImageDelegate(this));
+//! [21]
+
+//! [22]
+ QStringList labels;
+//! [22] //! [23]
+ labels << tr("Image") << tr("Mode") << tr("State");
+
+ imagesTable->horizontalHeader()->setDefaultSectionSize(90);
+ imagesTable->setColumnCount(3);
+ imagesTable->setHorizontalHeaderLabels(labels);
+ imagesTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
+ imagesTable->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed);
+ imagesTable->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed);
+ imagesTable->verticalHeader()->hide();
+//! [23]
+
+//! [24]
+ connect(imagesTable, SIGNAL(itemChanged(QTableWidgetItem*)),
+//! [24] //! [25]
+ this, SLOT(changeIcon()));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(imagesTable);
+ imagesGroupBox->setLayout(layout);
+}
+//! [25]
+
+//! [26]
+void MainWindow::createIconSizeGroupBox()
+{
+ iconSizeGroupBox = new QGroupBox(tr("Icon Size"));
+
+ smallRadioButton = new QRadioButton;
+ largeRadioButton = new QRadioButton;
+ toolBarRadioButton = new QRadioButton;
+ listViewRadioButton = new QRadioButton;
+ iconViewRadioButton = new QRadioButton;
+ tabBarRadioButton = new QRadioButton;
+ otherRadioButton = new QRadioButton(tr("Other:"));
+
+ otherSpinBox = new IconSizeSpinBox;
+ otherSpinBox->setRange(8, 128);
+ otherSpinBox->setValue(64);
+//! [26]
+
+//! [27]
+ connect(smallRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(largeRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(toolBarRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(listViewRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(iconViewRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(tabBarRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(otherRadioButton, SIGNAL(toggled(bool)),
+ this, SLOT(changeSize(bool)));
+ connect(otherSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeSize()));
+
+ QHBoxLayout *otherSizeLayout = new QHBoxLayout;
+ otherSizeLayout->addWidget(otherRadioButton);
+ otherSizeLayout->addWidget(otherSpinBox);
+ otherSizeLayout->addStretch();
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(smallRadioButton, 0, 0);
+ layout->addWidget(largeRadioButton, 1, 0);
+ layout->addWidget(toolBarRadioButton, 2, 0);
+ layout->addWidget(listViewRadioButton, 0, 1);
+ layout->addWidget(iconViewRadioButton, 1, 1);
+ layout->addWidget(tabBarRadioButton, 2, 1);
+ layout->addLayout(otherSizeLayout, 3, 0, 1, 2);
+ layout->setRowStretch(4, 1);
+ iconSizeGroupBox->setLayout(layout);
+}
+//! [27]
+
+//! [28]
+void MainWindow::createActions()
+{
+ addImagesAct = new QAction(tr("&Add Images..."), this);
+ addImagesAct->setShortcut(tr("Ctrl+A"));
+ connect(addImagesAct, SIGNAL(triggered()), this, SLOT(addImages()));
+
+ removeAllImagesAct = new QAction(tr("&Remove All Images"), this);
+ removeAllImagesAct->setShortcut(tr("Ctrl+R"));
+ connect(removeAllImagesAct, SIGNAL(triggered()),
+ this, SLOT(removeAllImages()));
+
+ exitAct = new QAction(tr("&Quit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ styleActionGroup = new QActionGroup(this);
+ foreach (QString styleName, QStyleFactory::keys()) {
+ QAction *action = new QAction(styleActionGroup);
+ action->setText(tr("%1 Style").arg(styleName));
+ action->setData(styleName);
+ action->setCheckable(true);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(changeStyle(bool)));
+ }
+
+ guessModeStateAct = new QAction(tr("&Guess Image Mode/State"), this);
+ guessModeStateAct->setCheckable(true);
+ guessModeStateAct->setChecked(true);
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+//! [28]
+
+//! [29]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(addImagesAct);
+ fileMenu->addAction(removeAllImagesAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ viewMenu = menuBar()->addMenu(tr("&View"));
+ foreach (QAction *action, styleActionGroup->actions())
+ viewMenu->addAction(action);
+ viewMenu->addSeparator();
+ viewMenu->addAction(guessModeStateAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [29]
+
+//! [30]
+void MainWindow::createContextMenu()
+{
+ imagesTable->setContextMenuPolicy(Qt::ActionsContextMenu);
+ imagesTable->addAction(addImagesAct);
+ imagesTable->addAction(removeAllImagesAct);
+}
+//! [30]
+
+//! [31]
+void MainWindow::checkCurrentStyle()
+{
+ foreach (QAction *action, styleActionGroup->actions()) {
+ QString styleName = action->data().toString();
+ QStyle *candidate = QStyleFactory::create(styleName);
+ Q_ASSERT(candidate);
+ if (candidate->metaObject()->className()
+ == QApplication::style()->metaObject()->className()) {
+ action->trigger();
+ return;
+ }
+ delete candidate;
+ }
+}
+//! [31]
diff --git a/examples/widgets/icons/mainwindow.h b/examples/widgets/icons/mainwindow.h
new file mode 100644
index 0000000000..1d2eab01a6
--- /dev/null
+++ b/examples/widgets/icons/mainwindow.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QIcon>
+#include <QList>
+#include <QMainWindow>
+#include <QPixmap>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QActionGroup;
+class QGroupBox;
+class QMenu;
+class QRadioButton;
+class QTableWidget;
+QT_END_NAMESPACE
+class IconPreviewArea;
+class IconSizeSpinBox;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void about();
+ void changeStyle(bool checked);
+ void changeSize(bool checked = true);
+ void changeIcon();
+ void addImages();
+ void removeAllImages();
+
+private:
+ void createPreviewGroupBox();
+ void createImagesGroupBox();
+ void createIconSizeGroupBox();
+ void createActions();
+ void createMenus();
+ void createContextMenu();
+ void checkCurrentStyle();
+
+ QWidget *centralWidget;
+
+ QGroupBox *previewGroupBox;
+ IconPreviewArea *previewArea;
+
+ QGroupBox *imagesGroupBox;
+ QTableWidget *imagesTable;
+
+ QGroupBox *iconSizeGroupBox;
+ QRadioButton *smallRadioButton;
+ QRadioButton *largeRadioButton;
+ QRadioButton *toolBarRadioButton;
+ QRadioButton *listViewRadioButton;
+ QRadioButton *iconViewRadioButton;
+ QRadioButton *tabBarRadioButton;
+ QRadioButton *otherRadioButton;
+ IconSizeSpinBox *otherSpinBox;
+
+ QMenu *fileMenu;
+ QMenu *viewMenu;
+ QMenu *helpMenu;
+ QAction *addImagesAct;
+ QAction *removeAllImagesAct;
+ QAction *exitAct;
+ QAction *guessModeStateAct;
+ QActionGroup *styleActionGroup;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/imageviewer/imageviewer.cpp b/examples/widgets/imageviewer/imageviewer.cpp
new file mode 100644
index 0000000000..8a8aaf9e96
--- /dev/null
+++ b/examples/widgets/imageviewer/imageviewer.cpp
@@ -0,0 +1,277 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "imageviewer.h"
+
+//! [0]
+ImageViewer::ImageViewer()
+{
+ imageLabel = new QLabel;
+ imageLabel->setBackgroundRole(QPalette::Base);
+ imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ imageLabel->setScaledContents(true);
+
+ scrollArea = new QScrollArea;
+ scrollArea->setBackgroundRole(QPalette::Dark);
+ scrollArea->setWidget(imageLabel);
+ setCentralWidget(scrollArea);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Image Viewer"));
+ resize(500, 400);
+}
+//! [0]
+
+//! [1]
+void ImageViewer::open()
+//! [1] //! [2]
+{
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"), QDir::currentPath());
+ if (!fileName.isEmpty()) {
+ QImage image(fileName);
+ if (image.isNull()) {
+ QMessageBox::information(this, tr("Image Viewer"),
+ tr("Cannot load %1.").arg(fileName));
+ return;
+ }
+//! [2] //! [3]
+ imageLabel->setPixmap(QPixmap::fromImage(image));
+//! [3] //! [4]
+ scaleFactor = 1.0;
+
+ printAct->setEnabled(true);
+ fitToWindowAct->setEnabled(true);
+ updateActions();
+
+ if (!fitToWindowAct->isChecked())
+ imageLabel->adjustSize();
+ }
+}
+//! [4]
+
+//! [5]
+void ImageViewer::print()
+//! [5] //! [6]
+{
+ Q_ASSERT(imageLabel->pixmap());
+#ifndef QT_NO_PRINTER
+//! [6] //! [7]
+ QPrintDialog dialog(&printer, this);
+//! [7] //! [8]
+ if (dialog.exec()) {
+ QPainter painter(&printer);
+ QRect rect = painter.viewport();
+ QSize size = imageLabel->pixmap()->size();
+ size.scale(rect.size(), Qt::KeepAspectRatio);
+ painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
+ painter.setWindow(imageLabel->pixmap()->rect());
+ painter.drawPixmap(0, 0, *imageLabel->pixmap());
+ }
+#endif
+}
+//! [8]
+
+//! [9]
+void ImageViewer::zoomIn()
+//! [9] //! [10]
+{
+ scaleImage(1.25);
+}
+
+void ImageViewer::zoomOut()
+{
+ scaleImage(0.8);
+}
+
+//! [10] //! [11]
+void ImageViewer::normalSize()
+//! [11] //! [12]
+{
+ imageLabel->adjustSize();
+ scaleFactor = 1.0;
+}
+//! [12]
+
+//! [13]
+void ImageViewer::fitToWindow()
+//! [13] //! [14]
+{
+ bool fitToWindow = fitToWindowAct->isChecked();
+ scrollArea->setWidgetResizable(fitToWindow);
+ if (!fitToWindow) {
+ normalSize();
+ }
+ updateActions();
+}
+//! [14]
+
+
+//! [15]
+void ImageViewer::about()
+//! [15] //! [16]
+{
+ QMessageBox::about(this, tr("About Image Viewer"),
+ tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
+ "and QScrollArea to display an image. QLabel is typically used "
+ "for displaying a 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. </p><p>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. </p><p>In addition the example "
+ "shows how to use QPainter to print an image.</p>"));
+}
+//! [16]
+
+//! [17]
+void ImageViewer::createActions()
+//! [17] //! [18]
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcut(tr("Ctrl+O"));
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ printAct = new QAction(tr("&Print..."), this);
+ printAct->setShortcut(tr("Ctrl+P"));
+ printAct->setEnabled(false);
+ connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcut(tr("Ctrl+Q"));
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ zoomInAct = new QAction(tr("Zoom &In (25%)"), this);
+ zoomInAct->setShortcut(tr("Ctrl++"));
+ zoomInAct->setEnabled(false);
+ connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
+
+ zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this);
+ zoomOutAct->setShortcut(tr("Ctrl+-"));
+ zoomOutAct->setEnabled(false);
+ connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
+
+ normalSizeAct = new QAction(tr("&Normal Size"), this);
+ normalSizeAct->setShortcut(tr("Ctrl+S"));
+ normalSizeAct->setEnabled(false);
+ connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize()));
+
+ fitToWindowAct = new QAction(tr("&Fit to Window"), this);
+ fitToWindowAct->setEnabled(false);
+ fitToWindowAct->setCheckable(true);
+ fitToWindowAct->setShortcut(tr("Ctrl+F"));
+ connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+//! [18]
+
+//! [19]
+void ImageViewer::createMenus()
+//! [19] //! [20]
+{
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(printAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ viewMenu = new QMenu(tr("&View"), this);
+ viewMenu->addAction(zoomInAct);
+ viewMenu->addAction(zoomOutAct);
+ viewMenu->addAction(normalSizeAct);
+ viewMenu->addSeparator();
+ viewMenu->addAction(fitToWindowAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(viewMenu);
+ menuBar()->addMenu(helpMenu);
+}
+//! [20]
+
+//! [21]
+void ImageViewer::updateActions()
+//! [21] //! [22]
+{
+ zoomInAct->setEnabled(!fitToWindowAct->isChecked());
+ zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
+ normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
+}
+//! [22]
+
+//! [23]
+void ImageViewer::scaleImage(double factor)
+//! [23] //! [24]
+{
+ Q_ASSERT(imageLabel->pixmap());
+ scaleFactor *= factor;
+ imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
+
+ adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
+ adjustScrollBar(scrollArea->verticalScrollBar(), factor);
+
+ zoomInAct->setEnabled(scaleFactor < 3.0);
+ zoomOutAct->setEnabled(scaleFactor > 0.333);
+}
+//! [24]
+
+//! [25]
+void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor)
+//! [25] //! [26]
+{
+ scrollBar->setValue(int(factor * scrollBar->value()
+ + ((factor - 1) * scrollBar->pageStep()/2)));
+}
+//! [26]
diff --git a/examples/widgets/imageviewer/imageviewer.h b/examples/widgets/imageviewer/imageviewer.h
new file mode 100644
index 0000000000..81ddf6c30a
--- /dev/null
+++ b/examples/widgets/imageviewer/imageviewer.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef IMAGEVIEWER_H
+#define IMAGEVIEWER_H
+
+#include <QMainWindow>
+#include <QPrinter>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QLabel;
+class QMenu;
+class QScrollArea;
+class QScrollBar;
+QT_END_NAMESPACE
+
+//! [0]
+class ImageViewer : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ ImageViewer();
+
+private slots:
+ void open();
+ void print();
+ void zoomIn();
+ void zoomOut();
+ void normalSize();
+ void fitToWindow();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ void updateActions();
+ void scaleImage(double factor);
+ void adjustScrollBar(QScrollBar *scrollBar, double factor);
+
+ QLabel *imageLabel;
+ QScrollArea *scrollArea;
+ double scaleFactor;
+
+#ifndef QT_NO_PRINTER
+ QPrinter printer;
+#endif
+
+ QAction *openAct;
+ QAction *printAct;
+ QAction *exitAct;
+ QAction *zoomInAct;
+ QAction *zoomOutAct;
+ QAction *normalSizeAct;
+ QAction *fitToWindowAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+
+ QMenu *fileMenu;
+ QMenu *viewMenu;
+ QMenu *helpMenu;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/imageviewer/imageviewer.pro b/examples/widgets/imageviewer/imageviewer.pro
new file mode 100644
index 0000000000..2c0624e773
--- /dev/null
+++ b/examples/widgets/imageviewer/imageviewer.pro
@@ -0,0 +1,15 @@
+HEADERS = imageviewer.h
+SOURCES = imageviewer.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/imageviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS imageviewer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/imageviewer
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: {
+ DEPLOYMENT_PLUGIN += qjpeg qmng qgif
+}
diff --git a/examples/widgets/imageviewer/main.cpp b/examples/widgets/imageviewer/main.cpp
new file mode 100644
index 0000000000..55a362a622
--- /dev/null
+++ b/examples/widgets/imageviewer/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "imageviewer.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ ImageViewer imageViewer;
+ imageViewer.show();
+ return app.exec();
+}
diff --git a/examples/widgets/lineedits/lineedits.pro b/examples/widgets/lineedits/lineedits.pro
new file mode 100644
index 0000000000..749c171e8f
--- /dev/null
+++ b/examples/widgets/lineedits/lineedits.pro
@@ -0,0 +1,14 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/lineedits
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS lineedits.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/lineedits
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C604
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/lineedits/main.cpp b/examples/widgets/lineedits/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/widgets/lineedits/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/lineedits/window.cpp
new file mode 100644
index 0000000000..427b6f5f5d
--- /dev/null
+++ b/examples/widgets/lineedits/window.cpp
@@ -0,0 +1,256 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
+
+ QLabel *echoLabel = new QLabel(tr("Mode:"));
+ QComboBox *echoComboBox = new QComboBox;
+ echoComboBox->addItem(tr("Normal"));
+ echoComboBox->addItem(tr("Password"));
+ echoComboBox->addItem(tr("PasswordEchoOnEdit"));
+ echoComboBox->addItem(tr("No Echo"));
+
+ echoLineEdit = new QLineEdit;
+ echoLineEdit->setFocus();
+//! [0]
+
+//! [1]
+ QGroupBox *validatorGroup = new QGroupBox(tr("Validator"));
+
+ QLabel *validatorLabel = new QLabel(tr("Type:"));
+ QComboBox *validatorComboBox = new QComboBox;
+ validatorComboBox->addItem(tr("No validator"));
+ validatorComboBox->addItem(tr("Integer validator"));
+ validatorComboBox->addItem(tr("Double validator"));
+
+ validatorLineEdit = new QLineEdit;
+//! [1]
+
+//! [2]
+ QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment"));
+
+ QLabel *alignmentLabel = new QLabel(tr("Type:"));
+ QComboBox *alignmentComboBox = new QComboBox;
+ alignmentComboBox->addItem(tr("Left"));
+ alignmentComboBox->addItem(tr("Centered"));
+ alignmentComboBox->addItem(tr("Right"));
+
+ alignmentLineEdit = new QLineEdit;
+//! [2]
+
+//! [3]
+ QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask"));
+
+ QLabel *inputMaskLabel = new QLabel(tr("Type:"));
+ QComboBox *inputMaskComboBox = new QComboBox;
+ inputMaskComboBox->addItem(tr("No mask"));
+ inputMaskComboBox->addItem(tr("Phone number"));
+ inputMaskComboBox->addItem(tr("ISO date"));
+ inputMaskComboBox->addItem(tr("License key"));
+
+ inputMaskLineEdit = new QLineEdit;
+//! [3]
+
+//! [4]
+ QGroupBox *accessGroup = new QGroupBox(tr("Access"));
+
+ QLabel *accessLabel = new QLabel(tr("Read-only:"));
+ QComboBox *accessComboBox = new QComboBox;
+ accessComboBox->addItem(tr("False"));
+ accessComboBox->addItem(tr("True"));
+
+ accessLineEdit = new QLineEdit;
+//! [4]
+
+//! [5]
+ connect(echoComboBox, SIGNAL(activated(int)),
+ this, SLOT(echoChanged(int)));
+ connect(validatorComboBox, SIGNAL(activated(int)),
+ this, SLOT(validatorChanged(int)));
+ connect(alignmentComboBox, SIGNAL(activated(int)),
+ this, SLOT(alignmentChanged(int)));
+ connect(inputMaskComboBox, SIGNAL(activated(int)),
+ this, SLOT(inputMaskChanged(int)));
+ connect(accessComboBox, SIGNAL(activated(int)),
+ this, SLOT(accessChanged(int)));
+//! [5]
+
+//! [6]
+ QGridLayout *echoLayout = new QGridLayout;
+ echoLayout->addWidget(echoLabel, 0, 0);
+ echoLayout->addWidget(echoComboBox, 0, 1);
+ echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2);
+ echoGroup->setLayout(echoLayout);
+//! [6]
+
+//! [7]
+ QGridLayout *validatorLayout = new QGridLayout;
+ validatorLayout->addWidget(validatorLabel, 0, 0);
+ validatorLayout->addWidget(validatorComboBox, 0, 1);
+ validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2);
+ validatorGroup->setLayout(validatorLayout);
+
+ QGridLayout *alignmentLayout = new QGridLayout;
+ alignmentLayout->addWidget(alignmentLabel, 0, 0);
+ alignmentLayout->addWidget(alignmentComboBox, 0, 1);
+ alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2);
+ alignmentGroup-> setLayout(alignmentLayout);
+
+ QGridLayout *inputMaskLayout = new QGridLayout;
+ inputMaskLayout->addWidget(inputMaskLabel, 0, 0);
+ inputMaskLayout->addWidget(inputMaskComboBox, 0, 1);
+ inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2);
+ inputMaskGroup->setLayout(inputMaskLayout);
+
+ QGridLayout *accessLayout = new QGridLayout;
+ accessLayout->addWidget(accessLabel, 0, 0);
+ accessLayout->addWidget(accessComboBox, 0, 1);
+ accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2);
+ accessGroup->setLayout(accessLayout);
+//! [7]
+
+//! [8]
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(echoGroup, 0, 0);
+ layout->addWidget(validatorGroup, 1, 0);
+ layout->addWidget(alignmentGroup, 2, 0);
+ layout->addWidget(inputMaskGroup, 0, 1);
+ layout->addWidget(accessGroup, 1, 1);
+ setLayout(layout);
+
+ setWindowTitle(tr("Line Edits"));
+}
+//! [8]
+
+//! [9]
+void Window::echoChanged(int index)
+{
+ switch (index) {
+ case 0:
+ echoLineEdit->setEchoMode(QLineEdit::Normal);
+ break;
+ case 1:
+ echoLineEdit->setEchoMode(QLineEdit::Password);
+ break;
+ case 2:
+ echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+ break;
+ case 3:
+ echoLineEdit->setEchoMode(QLineEdit::NoEcho);
+ }
+}
+//! [9]
+
+//! [10]
+void Window::validatorChanged(int index)
+{
+ switch (index) {
+ case 0:
+ validatorLineEdit->setValidator(0);
+ break;
+ case 1:
+ validatorLineEdit->setValidator(new QIntValidator(
+ validatorLineEdit));
+ break;
+ case 2:
+ validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
+ 999.0, 2, validatorLineEdit));
+ }
+
+ validatorLineEdit->clear();
+}
+//! [10]
+
+//! [11]
+void Window::alignmentChanged(int index)
+{
+ switch (index) {
+ case 0:
+ alignmentLineEdit->setAlignment(Qt::AlignLeft);
+ break;
+ case 1:
+ alignmentLineEdit->setAlignment(Qt::AlignCenter);
+ break;
+ case 2:
+ alignmentLineEdit->setAlignment(Qt::AlignRight);
+ }
+}
+//! [11]
+
+//! [12]
+void Window::inputMaskChanged(int index)
+{
+ switch (index) {
+ case 0:
+ inputMaskLineEdit->setInputMask("");
+ break;
+ case 1:
+ inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
+ break;
+ case 2:
+ inputMaskLineEdit->setInputMask("0000-00-00");
+ inputMaskLineEdit->setText("00000000");
+ inputMaskLineEdit->setCursorPosition(0);
+ break;
+ case 3:
+ inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
+ }
+}
+//! [12]
+
+//! [13]
+void Window::accessChanged(int index)
+{
+ switch (index) {
+ case 0:
+ accessLineEdit->setReadOnly(false);
+ break;
+ case 1:
+ accessLineEdit->setReadOnly(true);
+ }
+}
+//! [13]
diff --git a/examples/widgets/lineedits/window.h b/examples/widgets/lineedits/window.h
new file mode 100644
index 0000000000..6bda9d0f5a
--- /dev/null
+++ b/examples/widgets/lineedits/window.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+class QLineEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+public slots:
+ void echoChanged(int);
+ void validatorChanged(int);
+ void alignmentChanged(int);
+ void inputMaskChanged(int);
+ void accessChanged(int);
+
+private:
+ QLineEdit *echoLineEdit;
+ QLineEdit *validatorLineEdit;
+ QLineEdit *alignmentLineEdit;
+ QLineEdit *inputMaskLineEdit;
+ QLineEdit *accessLineEdit;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/movie/animation.mng b/examples/widgets/movie/animation.mng
new file mode 100644
index 0000000000..12b688aac6
--- /dev/null
+++ b/examples/widgets/movie/animation.mng
Binary files differ
diff --git a/examples/widgets/movie/main.cpp b/examples/widgets/movie/main.cpp
new file mode 100644
index 0000000000..3863234936
--- /dev/null
+++ b/examples/widgets/movie/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "movieplayer.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MoviePlayer player;
+ player.show();
+ return app.exec();
+}
diff --git a/examples/widgets/movie/movie.pro b/examples/widgets/movie/movie.pro
new file mode 100644
index 0000000000..82bc3c4a4d
--- /dev/null
+++ b/examples/widgets/movie/movie.pro
@@ -0,0 +1,19 @@
+HEADERS = movieplayer.h
+SOURCES = main.cpp \
+ movieplayer.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/movie
+sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro animation.mng
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/movie
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: {
+ addFiles.files += *.mng
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+ DEPLOYMENT_PLUGIN += qmng
+}
+
diff --git a/examples/widgets/movie/movieplayer.cpp b/examples/widgets/movie/movieplayer.cpp
new file mode 100644
index 0000000000..f4d2279729
--- /dev/null
+++ b/examples/widgets/movie/movieplayer.cpp
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "movieplayer.h"
+
+MoviePlayer::MoviePlayer(QWidget *parent)
+ : QWidget(parent)
+{
+ movie = new QMovie(this);
+ movie->setCacheMode(QMovie::CacheAll);
+
+ movieLabel = new QLabel(tr("No movie loaded"));
+ movieLabel->setAlignment(Qt::AlignCenter);
+ movieLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+ movieLabel->setBackgroundRole(QPalette::Dark);
+ movieLabel->setAutoFillBackground(true);
+
+ currentMovieDirectory = "movies";
+
+ createControls();
+ createButtons();
+
+ connect(movie, SIGNAL(frameChanged(int)), this, SLOT(updateFrameSlider()));
+ connect(movie, SIGNAL(stateChanged(QMovie::MovieState)),
+ this, SLOT(updateButtons()));
+ connect(fitCheckBox, SIGNAL(clicked()), this, SLOT(fitToWindow()));
+ connect(frameSlider, SIGNAL(valueChanged(int)), this, SLOT(goToFrame(int)));
+ connect(speedSpinBox, SIGNAL(valueChanged(int)),
+ movie, SLOT(setSpeed(int)));
+
+ mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(movieLabel);
+ mainLayout->addLayout(controlsLayout);
+ mainLayout->addLayout(buttonsLayout);
+ setLayout(mainLayout);
+
+ updateFrameSlider();
+ updateButtons();
+
+ setWindowTitle(tr("Movie Player"));
+ resize(400, 400);
+}
+
+void MoviePlayer::open()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open a Movie"),
+ currentMovieDirectory);
+ if (!fileName.isEmpty())
+ openFile(fileName);
+}
+
+void MoviePlayer::openFile(const QString &fileName)
+{
+ currentMovieDirectory = QFileInfo(fileName).path();
+
+ movie->stop();
+ movieLabel->setMovie(movie);
+ movie->setFileName(fileName);
+ movie->start();
+
+ updateFrameSlider();
+ updateButtons();
+}
+
+void MoviePlayer::goToFrame(int frame)
+{
+ movie->jumpToFrame(frame);
+}
+
+void MoviePlayer::fitToWindow()
+{
+ movieLabel->setScaledContents(fitCheckBox->isChecked());
+}
+
+void MoviePlayer::updateFrameSlider()
+{
+ bool hasFrames = (movie->currentFrameNumber() >= 0);
+
+ if (hasFrames) {
+ if (movie->frameCount() > 0) {
+ frameSlider->setMaximum(movie->frameCount() - 1);
+ } else {
+ if (movie->currentFrameNumber() > frameSlider->maximum())
+ frameSlider->setMaximum(movie->currentFrameNumber());
+ }
+ frameSlider->setValue(movie->currentFrameNumber());
+ } else {
+ frameSlider->setMaximum(0);
+ }
+ frameLabel->setEnabled(hasFrames);
+ frameSlider->setEnabled(hasFrames);
+}
+
+void MoviePlayer::updateButtons()
+{
+ playButton->setEnabled(movie->isValid() && movie->frameCount() != 1
+ && movie->state() == QMovie::NotRunning);
+ pauseButton->setEnabled(movie->state() != QMovie::NotRunning);
+ pauseButton->setChecked(movie->state() == QMovie::Paused);
+ stopButton->setEnabled(movie->state() != QMovie::NotRunning);
+}
+
+void MoviePlayer::createControls()
+{
+ fitCheckBox = new QCheckBox(tr("Fit to Window"));
+
+ frameLabel = new QLabel(tr("Current frame:"));
+
+ frameSlider = new QSlider(Qt::Horizontal);
+ frameSlider->setTickPosition(QSlider::TicksBelow);
+ frameSlider->setTickInterval(10);
+
+ speedLabel = new QLabel(tr("Speed:"));
+
+ speedSpinBox = new QSpinBox;
+ speedSpinBox->setRange(1, 9999);
+ speedSpinBox->setValue(100);
+ speedSpinBox->setSuffix(tr("%"));
+
+ controlsLayout = new QGridLayout;
+ controlsLayout->addWidget(fitCheckBox, 0, 0, 1, 2);
+ controlsLayout->addWidget(frameLabel, 1, 0);
+ controlsLayout->addWidget(frameSlider, 1, 1, 1, 2);
+ controlsLayout->addWidget(speedLabel, 2, 0);
+ controlsLayout->addWidget(speedSpinBox, 2, 1);
+}
+
+void MoviePlayer::createButtons()
+{
+ QSize iconSize(36, 36);
+
+ openButton = new QToolButton;
+ openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
+ openButton->setIconSize(iconSize);
+ openButton->setToolTip(tr("Open File"));
+ connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
+
+ playButton = new QToolButton;
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ playButton->setIconSize(iconSize);
+ playButton->setToolTip(tr("Play"));
+ connect(playButton, SIGNAL(clicked()), movie, SLOT(start()));
+
+ pauseButton = new QToolButton;
+ pauseButton->setCheckable(true);
+ pauseButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
+ pauseButton->setIconSize(iconSize);
+ pauseButton->setToolTip(tr("Pause"));
+ connect(pauseButton, SIGNAL(clicked(bool)), movie, SLOT(setPaused(bool)));
+
+ stopButton = new QToolButton;
+ stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
+ stopButton->setIconSize(iconSize);
+ stopButton->setToolTip(tr("Stop"));
+ connect(stopButton, SIGNAL(clicked()), movie, SLOT(stop()));
+
+ quitButton = new QToolButton;
+ quitButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
+ quitButton->setIconSize(iconSize);
+ quitButton->setToolTip(tr("Quit"));
+ connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch();
+ buttonsLayout->addWidget(openButton);
+ buttonsLayout->addWidget(playButton);
+ buttonsLayout->addWidget(pauseButton);
+ buttonsLayout->addWidget(stopButton);
+ buttonsLayout->addWidget(quitButton);
+ buttonsLayout->addStretch();
+}
diff --git a/examples/widgets/movie/movieplayer.h b/examples/widgets/movie/movieplayer.h
new file mode 100644
index 0000000000..415a2bebb5
--- /dev/null
+++ b/examples/widgets/movie/movieplayer.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOVIEPLAYER_H
+#define MOVIEPLAYER_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QGridLayout;
+class QHBoxLayout;
+class QLabel;
+class QMovie;
+class QSlider;
+class QSpinBox;
+class QToolButton;
+class QVBoxLayout;
+QT_END_NAMESPACE
+
+class MoviePlayer : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MoviePlayer(QWidget *parent = 0);
+ void openFile(const QString &fileName);
+
+private slots:
+ void open();
+ void goToFrame(int frame);
+ void fitToWindow();
+ void updateButtons();
+ void updateFrameSlider();
+
+private:
+ void createControls();
+ void createButtons();
+
+ QString currentMovieDirectory;
+ QLabel *movieLabel;
+ QMovie *movie;
+ QToolButton *openButton;
+ QToolButton *playButton;
+ QToolButton *pauseButton;
+ QToolButton *stopButton;
+ QToolButton *quitButton;
+ QCheckBox *fitCheckBox;
+ QSlider *frameSlider;
+ QSpinBox *speedSpinBox;
+ QLabel *frameLabel;
+ QLabel *speedLabel;
+
+ QGridLayout *controlsLayout;
+ QHBoxLayout *buttonsLayout;
+ QVBoxLayout *mainLayout;
+};
+
+#endif
diff --git a/examples/widgets/scribble/main.cpp b/examples/widgets/scribble/main.cpp
new file mode 100644
index 0000000000..01c8adae53
--- /dev/null
+++ b/examples/widgets/scribble/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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/scribble/mainwindow.cpp
new file mode 100644
index 0000000000..a45bf07928
--- /dev/null
+++ b/examples/widgets/scribble/mainwindow.cpp
@@ -0,0 +1,250 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "scribblearea.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ scribbleArea = new ScribbleArea;
+ setCentralWidget(scribbleArea);
+
+ createActions();
+ createMenus();
+
+ setWindowTitle(tr("Scribble"));
+ resize(500, 500);
+}
+//! [0]
+
+//! [1]
+void MainWindow::closeEvent(QCloseEvent *event)
+//! [1] //! [2]
+{
+ if (maybeSave()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+//! [2]
+
+//! [3]
+void MainWindow::open()
+//! [3] //! [4]
+{
+ if (maybeSave()) {
+ QString fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"), QDir::currentPath());
+ if (!fileName.isEmpty())
+ scribbleArea->openImage(fileName);
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::save()
+//! [5] //! [6]
+{
+ QAction *action = qobject_cast<QAction *>(sender());
+ QByteArray fileFormat = action->data().toByteArray();
+ saveFile(fileFormat);
+}
+//! [6]
+
+//! [7]
+void MainWindow::penColor()
+//! [7] //! [8]
+{
+ QColor newColor = QColorDialog::getColor(scribbleArea->penColor());
+ if (newColor.isValid())
+ scribbleArea->setPenColor(newColor);
+}
+//! [8]
+
+//! [9]
+void MainWindow::penWidth()
+//! [9] //! [10]
+{
+ bool ok;
+ int newWidth = QInputDialog::getInteger(this, tr("Scribble"),
+ tr("Select pen width:"),
+ scribbleArea->penWidth(),
+ 1, 50, 1, &ok);
+ if (ok)
+ scribbleArea->setPenWidth(newWidth);
+}
+//! [10]
+
+//! [11]
+void MainWindow::about()
+//! [11] //! [12]
+{
+ QMessageBox::about(this, tr("About Scribble"),
+ tr("<p>The <b>Scribble</b> example shows how to use QMainWindow as the "
+ "base widget for an application, and how to reimplement some of "
+ "QWidget's event handlers to receive the events generated for "
+ "the application's widgets:</p><p> We reimplement the mouse event "
+ "handlers to facilitate 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.</p><p> The example also demonstrates "
+ "how to use QPainter to draw an image in real time, as well as "
+ "to repaint widgets.</p>"));
+}
+//! [12]
+
+//! [13]
+void MainWindow::createActions()
+//! [13] //! [14]
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ foreach (QByteArray format, QImageWriter::supportedImageFormats()) {
+ QString text = tr("%1...").arg(QString(format).toUpper());
+
+ QAction *action = new QAction(text, this);
+ action->setData(format);
+ connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ saveAsActs.append(action);
+ }
+
+ printAct = new QAction(tr("&Print..."), this);
+ connect(printAct, SIGNAL(triggered()), scribbleArea, SLOT(print()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ penColorAct = new QAction(tr("&Pen Color..."), this);
+ connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor()));
+
+ penWidthAct = new QAction(tr("Pen &Width..."), this);
+ connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth()));
+
+ clearScreenAct = new QAction(tr("&Clear Screen"), this);
+ clearScreenAct->setShortcut(tr("Ctrl+L"));
+ connect(clearScreenAct, SIGNAL(triggered()),
+ scribbleArea, SLOT(clearImage()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+//! [14]
+
+//! [15]
+void MainWindow::createMenus()
+//! [15] //! [16]
+{
+ saveAsMenu = new QMenu(tr("&Save As"), this);
+ foreach (QAction *action, saveAsActs)
+ saveAsMenu->addAction(action);
+
+ fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(openAct);
+ fileMenu->addMenu(saveAsMenu);
+ fileMenu->addAction(printAct);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAct);
+
+ optionMenu = new QMenu(tr("&Options"), this);
+ optionMenu->addAction(penColorAct);
+ optionMenu->addAction(penWidthAct);
+ optionMenu->addSeparator();
+ optionMenu->addAction(clearScreenAct);
+
+ helpMenu = new QMenu(tr("&Help"), this);
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(optionMenu);
+ menuBar()->addMenu(helpMenu);
+}
+//! [16]
+
+//! [17]
+bool MainWindow::maybeSave()
+//! [17] //! [18]
+{
+ if (scribbleArea->isModified()) {
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Scribble"),
+ tr("The image has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save) {
+ return saveFile("png");
+ } else if (ret == QMessageBox::Cancel) {
+ return false;
+ }
+ }
+ return true;
+}
+//! [18]
+
+//! [19]
+bool MainWindow::saveFile(const QByteArray &fileFormat)
+//! [19] //! [20]
+{
+ QString initialPath = QDir::currentPath() + "/untitled." + fileFormat;
+
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
+ initialPath,
+ tr("%1 Files (*.%2);;All Files (*)")
+ .arg(QString(fileFormat.toUpper()))
+ .arg(QString(fileFormat)));
+ if (fileName.isEmpty()) {
+ return false;
+ } else {
+ return scribbleArea->saveImage(fileName, fileFormat);
+ }
+}
+//! [20]
diff --git a/examples/widgets/scribble/mainwindow.h b/examples/widgets/scribble/mainwindow.h
new file mode 100644
index 0000000000..547d35f04f
--- /dev/null
+++ b/examples/widgets/scribble/mainwindow.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+
+class ScribbleArea;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+protected:
+ void closeEvent(QCloseEvent *event);
+
+private slots:
+ void open();
+ void save();
+ void penColor();
+ void penWidth();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+ bool maybeSave();
+ bool saveFile(const QByteArray &fileFormat);
+
+ ScribbleArea *scribbleArea;
+
+ QMenu *saveAsMenu;
+ QMenu *fileMenu;
+ QMenu *optionMenu;
+ QMenu *helpMenu;
+
+ QAction *openAct;
+ QList<QAction *> saveAsActs;
+ QAction *exitAct;
+ QAction *penColorAct;
+ QAction *penWidthAct;
+ QAction *printAct;
+ QAction *clearScreenAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/scribble/scribble.pro b/examples/widgets/scribble/scribble.pro
new file mode 100644
index 0000000000..90084b5b98
--- /dev/null
+++ b/examples/widgets/scribble/scribble.pro
@@ -0,0 +1,13 @@
+HEADERS = mainwindow.h \
+ scribblearea.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ scribblearea.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/scribble
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS scribble.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/scribble
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/scribble/scribblearea.cpp b/examples/widgets/scribble/scribblearea.cpp
new file mode 100644
index 0000000000..5854e34f42
--- /dev/null
+++ b/examples/widgets/scribble/scribblearea.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "scribblearea.h"
+
+//! [0]
+ScribbleArea::ScribbleArea(QWidget *parent)
+ : QWidget(parent)
+{
+ setAttribute(Qt::WA_StaticContents);
+ modified = false;
+ scribbling = false;
+ myPenWidth = 1;
+ myPenColor = Qt::blue;
+}
+//! [0]
+
+//! [1]
+bool ScribbleArea::openImage(const QString &fileName)
+//! [1] //! [2]
+{
+ QImage loadedImage;
+ if (!loadedImage.load(fileName))
+ return false;
+
+ QSize newSize = loadedImage.size().expandedTo(size());
+ resizeImage(&loadedImage, newSize);
+ image = loadedImage;
+ modified = false;
+ update();
+ return true;
+}
+//! [2]
+
+//! [3]
+bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat)
+//! [3] //! [4]
+{
+ QImage visibleImage = image;
+ resizeImage(&visibleImage, size());
+
+ if (visibleImage.save(fileName, fileFormat)) {
+ modified = false;
+ return true;
+ } else {
+ return false;
+ }
+}
+//! [4]
+
+//! [5]
+void ScribbleArea::setPenColor(const QColor &newColor)
+//! [5] //! [6]
+{
+ myPenColor = newColor;
+}
+//! [6]
+
+//! [7]
+void ScribbleArea::setPenWidth(int newWidth)
+//! [7] //! [8]
+{
+ myPenWidth = newWidth;
+}
+//! [8]
+
+//! [9]
+void ScribbleArea::clearImage()
+//! [9] //! [10]
+{
+ image.fill(qRgb(255, 255, 255));
+ modified = true;
+ update();
+}
+//! [10]
+
+//! [11]
+void ScribbleArea::mousePressEvent(QMouseEvent *event)
+//! [11] //! [12]
+{
+ if (event->button() == Qt::LeftButton) {
+ lastPoint = event->pos();
+ scribbling = true;
+ }
+}
+
+void ScribbleArea::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && scribbling)
+ drawLineTo(event->pos());
+}
+
+void ScribbleArea::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && scribbling) {
+ drawLineTo(event->pos());
+ scribbling = false;
+ }
+}
+
+//! [12] //! [13]
+void ScribbleArea::paintEvent(QPaintEvent *event)
+//! [13] //! [14]
+{
+ QPainter painter(this);
+ QRect dirtyRect = event->rect();
+ painter.drawImage(dirtyRect, image, dirtyRect);
+}
+//! [14]
+
+//! [15]
+void ScribbleArea::resizeEvent(QResizeEvent *event)
+//! [15] //! [16]
+{
+ if (width() > image.width() || height() > image.height()) {
+ int newWidth = qMax(width() + 128, image.width());
+ int newHeight = qMax(height() + 128, image.height());
+ resizeImage(&image, QSize(newWidth, newHeight));
+ update();
+ }
+ QWidget::resizeEvent(event);
+}
+//! [16]
+
+//! [17]
+void ScribbleArea::drawLineTo(const QPoint &endPoint)
+//! [17] //! [18]
+{
+ QPainter painter(&image);
+ painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
+ Qt::RoundJoin));
+ painter.drawLine(lastPoint, endPoint);
+ modified = true;
+
+ int rad = (myPenWidth / 2) + 2;
+ update(QRect(lastPoint, endPoint).normalized()
+ .adjusted(-rad, -rad, +rad, +rad));
+ lastPoint = endPoint;
+}
+//! [18]
+
+//! [19]
+void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
+//! [19] //! [20]
+{
+ if (image->size() == newSize)
+ return;
+
+ QImage newImage(newSize, QImage::Format_RGB32);
+ newImage.fill(qRgb(255, 255, 255));
+ QPainter painter(&newImage);
+ painter.drawImage(QPoint(0, 0), *image);
+ *image = newImage;
+}
+//! [20]
+
+//! [21]
+void ScribbleArea::print()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+
+ QPrintDialog *printDialog = new QPrintDialog(&printer, this);
+//! [21] //! [22]
+ if (printDialog->exec() == QDialog::Accepted) {
+ QPainter painter(&printer);
+ QRect rect = painter.viewport();
+ QSize size = image.size();
+ size.scale(rect.size(), Qt::KeepAspectRatio);
+ painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
+ painter.setWindow(image.rect());
+ painter.drawImage(0, 0, image);
+ }
+#endif // QT_NO_PRINTER
+}
+//! [22]
diff --git a/examples/widgets/scribble/scribblearea.h b/examples/widgets/scribble/scribblearea.h
new file mode 100644
index 0000000000..c93102df42
--- /dev/null
+++ b/examples/widgets/scribble/scribblearea.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCRIBBLEAREA_H
+#define SCRIBBLEAREA_H
+
+#include <QColor>
+#include <QImage>
+#include <QPoint>
+#include <QWidget>
+
+//! [0]
+class ScribbleArea : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ScribbleArea(QWidget *parent = 0);
+
+ bool openImage(const QString &fileName);
+ bool saveImage(const QString &fileName, const char *fileFormat);
+ void setPenColor(const QColor &newColor);
+ void setPenWidth(int newWidth);
+
+ bool isModified() const { return modified; }
+ QColor penColor() const { return myPenColor; }
+ int penWidth() const { return myPenWidth; }
+
+public slots:
+ void clearImage();
+ void print();
+
+protected:
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ void drawLineTo(const QPoint &endPoint);
+ void resizeImage(QImage *image, const QSize &newSize);
+
+ bool modified;
+ bool scribbling;
+ int myPenWidth;
+ QColor myPenColor;
+ QImage image;
+ QPoint lastPoint;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/shapedclock/main.cpp b/examples/widgets/shapedclock/main.cpp
new file mode 100644
index 0000000000..9b7f951a48
--- /dev/null
+++ b/examples/widgets/shapedclock/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "shapedclock.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ ShapedClock clock;
+ clock.show();
+ return app.exec();
+}
diff --git a/examples/widgets/shapedclock/shapedclock.cpp b/examples/widgets/shapedclock/shapedclock.cpp
new file mode 100644
index 0000000000..71c27bff14
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.cpp
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "shapedclock.h"
+
+//! [0]
+ShapedClock::ShapedClock(QWidget *parent)
+ : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint)
+{
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(update()));
+ timer->start(1000);
+
+ QAction *quitAction = new QAction(tr("E&xit"), this);
+ quitAction->setShortcut(tr("Ctrl+Q"));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ addAction(quitAction);
+
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+ setToolTip(tr("Drag the clock with the left mouse button.\n"
+ "Use the right mouse button to open a context menu."));
+ setWindowTitle(tr("Shaped Analog Clock"));
+}
+//! [0]
+
+//! [1]
+void ShapedClock::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ dragPosition = event->globalPos() - frameGeometry().topLeft();
+ event->accept();
+ }
+}
+//! [1]
+
+//! [2]
+void ShapedClock::mouseMoveEvent(QMouseEvent *event)
+{
+ if (event->buttons() & Qt::LeftButton) {
+ move(event->globalPos() - dragPosition);
+ event->accept();
+ }
+}
+//! [2]
+
+//! [3]
+void ShapedClock::paintEvent(QPaintEvent *)
+{
+ static const QPoint hourHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -40)
+ };
+ static const QPoint minuteHand[3] = {
+ QPoint(7, 8),
+ QPoint(-7, 8),
+ QPoint(0, -70)
+ };
+
+ QColor hourColor(127, 0, 127);
+ QColor minuteColor(0, 127, 127, 191);
+
+ int side = qMin(width(), height());
+ QTime time = QTime::currentTime();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ painter.translate(width() / 2, height() / 2);
+ painter.scale(side / 200.0, side / 200.0);
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(hourColor);
+
+ painter.save();
+ painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
+ painter.drawConvexPolygon(hourHand, 3);
+ painter.restore();
+
+ painter.setPen(hourColor);
+
+ for (int i = 0; i < 12; ++i) {
+ painter.drawLine(88, 0, 96, 0);
+ painter.rotate(30.0);
+ }
+
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(minuteColor);
+
+ painter.save();
+ painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
+ painter.drawConvexPolygon(minuteHand, 3);
+ painter.restore();
+
+ painter.setPen(minuteColor);
+
+ for (int j = 0; j < 60; ++j) {
+ if ((j % 5) != 0)
+ painter.drawLine(92, 0, 96, 0);
+ painter.rotate(6.0);
+ }
+}
+//! [3]
+
+//! [4]
+void ShapedClock::resizeEvent(QResizeEvent * /* event */)
+{
+ int side = qMin(width(), height());
+ QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side,
+ side, QRegion::Ellipse);
+ setMask(maskedRegion);
+}
+//! [4]
+
+//! [5]
+QSize ShapedClock::sizeHint() const
+{
+ return QSize(100, 100);
+}
+//! [5]
diff --git a/examples/widgets/shapedclock/shapedclock.h b/examples/widgets/shapedclock/shapedclock.h
new file mode 100644
index 0000000000..b34d34c2e5
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHAPEDCLOCK_H
+#define SHAPEDCLOCK_H
+
+#include <QWidget>
+
+//! [0]
+class ShapedClock : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ShapedClock(QWidget *parent = 0);
+ QSize sizeHint() const;
+
+protected:
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ QPoint dragPosition;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/shapedclock/shapedclock.pro b/examples/widgets/shapedclock/shapedclock.pro
new file mode 100644
index 0000000000..1286951943
--- /dev/null
+++ b/examples/widgets/shapedclock/shapedclock.pro
@@ -0,0 +1,14 @@
+HEADERS = shapedclock.h
+SOURCES = shapedclock.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/shapedclock
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS shapedclock.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/shapedclock
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C605
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/sliders/main.cpp b/examples/widgets/sliders/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/widgets/sliders/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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.pro b/examples/widgets/sliders/sliders.pro
new file mode 100644
index 0000000000..1d9e779b8a
--- /dev/null
+++ b/examples/widgets/sliders/sliders.pro
@@ -0,0 +1,13 @@
+HEADERS = slidersgroup.h \
+ window.h
+SOURCES = main.cpp \
+ slidersgroup.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/sliders
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS sliders.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/sliders
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/sliders/slidersgroup.cpp b/examples/widgets/sliders/slidersgroup.cpp
new file mode 100644
index 0000000000..4ead1cc226
--- /dev/null
+++ b/examples/widgets/sliders/slidersgroup.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "slidersgroup.h"
+
+//! [0]
+SlidersGroup::SlidersGroup(Qt::Orientation orientation, const QString &title,
+ QWidget *parent)
+ : QGroupBox(title, parent)
+{
+ slider = new QSlider(orientation);
+ slider->setFocusPolicy(Qt::StrongFocus);
+ slider->setTickPosition(QSlider::TicksBothSides);
+ slider->setTickInterval(10);
+ slider->setSingleStep(1);
+
+ scrollBar = new QScrollBar(orientation);
+ scrollBar->setFocusPolicy(Qt::StrongFocus);
+
+ dial = new QDial;
+ dial->setFocusPolicy(Qt::StrongFocus);
+
+ connect(slider, SIGNAL(valueChanged(int)), scrollBar, SLOT(setValue(int)));
+ connect(scrollBar, SIGNAL(valueChanged(int)), dial, SLOT(setValue(int)));
+ connect(dial, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
+//! [0] //! [1]
+ connect(dial, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
+//! [1] //! [2]
+
+//! [2] //! [3]
+ QBoxLayout::Direction direction;
+//! [3] //! [4]
+
+ if (orientation == Qt::Horizontal)
+ direction = QBoxLayout::TopToBottom;
+ else
+ direction = QBoxLayout::LeftToRight;
+
+ QBoxLayout *slidersLayout = new QBoxLayout(direction);
+ slidersLayout->addWidget(slider);
+ slidersLayout->addWidget(scrollBar);
+ slidersLayout->addWidget(dial);
+ setLayout(slidersLayout);
+}
+//! [4]
+
+//! [5]
+void SlidersGroup::setValue(int value)
+//! [5] //! [6]
+{
+ slider->setValue(value);
+}
+//! [6]
+
+//! [7]
+void SlidersGroup::setMinimum(int value)
+//! [7] //! [8]
+{
+ slider->setMinimum(value);
+ scrollBar->setMinimum(value);
+ dial->setMinimum(value);
+}
+//! [8]
+
+//! [9]
+void SlidersGroup::setMaximum(int value)
+//! [9] //! [10]
+{
+ slider->setMaximum(value);
+ scrollBar->setMaximum(value);
+ dial->setMaximum(value);
+}
+//! [10]
+
+//! [11]
+void SlidersGroup::invertAppearance(bool invert)
+//! [11] //! [12]
+{
+ slider->setInvertedAppearance(invert);
+ scrollBar->setInvertedAppearance(invert);
+ dial->setInvertedAppearance(invert);
+}
+//! [12]
+
+//! [13]
+void SlidersGroup::invertKeyBindings(bool invert)
+//! [13] //! [14]
+{
+ slider->setInvertedControls(invert);
+ scrollBar->setInvertedControls(invert);
+ dial->setInvertedControls(invert);
+}
+//! [14]
diff --git a/examples/widgets/sliders/slidersgroup.h b/examples/widgets/sliders/slidersgroup.h
new file mode 100644
index 0000000000..dbfba22aea
--- /dev/null
+++ b/examples/widgets/sliders/slidersgroup.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SLIDERSGROUP_H
+#define SLIDERSGROUP_H
+
+#include <QGroupBox>
+
+QT_BEGIN_NAMESPACE
+class QDial;
+class QScrollBar;
+class QSlider;
+QT_END_NAMESPACE
+
+//! [0]
+class SlidersGroup : public QGroupBox
+{
+ Q_OBJECT
+
+public:
+ SlidersGroup(Qt::Orientation orientation, const QString &title,
+ QWidget *parent = 0);
+
+signals:
+ void valueChanged(int value);
+
+public slots:
+ void setValue(int value);
+ void setMinimum(int value);
+ void setMaximum(int value);
+ void invertAppearance(bool invert);
+ void invertKeyBindings(bool invert);
+
+private:
+ QSlider *slider;
+ QScrollBar *scrollBar;
+ QDial *dial;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/sliders/window.cpp b/examples/widgets/sliders/window.cpp
new file mode 100644
index 0000000000..9286910a19
--- /dev/null
+++ b/examples/widgets/sliders/window.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "slidersgroup.h"
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ horizontalSliders = new SlidersGroup(Qt::Horizontal, tr("Horizontal"));
+ verticalSliders = new SlidersGroup(Qt::Vertical, tr("Vertical"));
+
+ stackedWidget = new QStackedWidget;
+ stackedWidget->addWidget(horizontalSliders);
+ stackedWidget->addWidget(verticalSliders);
+
+ createControls(tr("Controls"));
+//! [0]
+
+//! [1]
+ connect(horizontalSliders, SIGNAL(valueChanged(int)),
+//! [1] //! [2]
+ verticalSliders, SLOT(setValue(int)));
+ connect(verticalSliders, SIGNAL(valueChanged(int)),
+ valueSpinBox, SLOT(setValue(int)));
+ connect(valueSpinBox, SIGNAL(valueChanged(int)),
+ horizontalSliders, SLOT(setValue(int)));
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(controlsGroup);
+ layout->addWidget(stackedWidget);
+ setLayout(layout);
+
+ minimumSpinBox->setValue(0);
+ maximumSpinBox->setValue(20);
+ valueSpinBox->setValue(5);
+
+ setWindowTitle(tr("Sliders"));
+}
+//! [2]
+
+//! [3]
+void Window::createControls(const QString &title)
+//! [3] //! [4]
+{
+ controlsGroup = new QGroupBox(title);
+
+ minimumLabel = new QLabel(tr("Minimum value:"));
+ maximumLabel = new QLabel(tr("Maximum value:"));
+ valueLabel = new QLabel(tr("Current value:"));
+
+ invertedAppearance = new QCheckBox(tr("Inverted appearance"));
+ invertedKeyBindings = new QCheckBox(tr("Inverted key bindings"));
+
+//! [4] //! [5]
+ minimumSpinBox = new QSpinBox;
+//! [5] //! [6]
+ minimumSpinBox->setRange(-100, 100);
+ minimumSpinBox->setSingleStep(1);
+
+ maximumSpinBox = new QSpinBox;
+ maximumSpinBox->setRange(-100, 100);
+ maximumSpinBox->setSingleStep(1);
+
+ valueSpinBox = new QSpinBox;
+ valueSpinBox->setRange(-100, 100);
+ valueSpinBox->setSingleStep(1);
+
+ orientationCombo = new QComboBox;
+ orientationCombo->addItem(tr("Horizontal slider-like widgets"));
+ orientationCombo->addItem(tr("Vertical slider-like widgets"));
+
+//! [6] //! [7]
+ connect(orientationCombo, SIGNAL(activated(int)),
+//! [7] //! [8]
+ stackedWidget, SLOT(setCurrentIndex(int)));
+ connect(minimumSpinBox, SIGNAL(valueChanged(int)),
+ horizontalSliders, SLOT(setMinimum(int)));
+ connect(minimumSpinBox, SIGNAL(valueChanged(int)),
+ verticalSliders, SLOT(setMinimum(int)));
+ connect(maximumSpinBox, SIGNAL(valueChanged(int)),
+ horizontalSliders, SLOT(setMaximum(int)));
+ connect(maximumSpinBox, SIGNAL(valueChanged(int)),
+ verticalSliders, SLOT(setMaximum(int)));
+ connect(invertedAppearance, SIGNAL(toggled(bool)),
+ horizontalSliders, SLOT(invertAppearance(bool)));
+ connect(invertedAppearance, SIGNAL(toggled(bool)),
+ verticalSliders, SLOT(invertAppearance(bool)));
+ connect(invertedKeyBindings, SIGNAL(toggled(bool)),
+ horizontalSliders, SLOT(invertKeyBindings(bool)));
+ connect(invertedKeyBindings, SIGNAL(toggled(bool)),
+ verticalSliders, SLOT(invertKeyBindings(bool)));
+
+ QGridLayout *controlsLayout = new QGridLayout;
+ controlsLayout->addWidget(minimumLabel, 0, 0);
+ controlsLayout->addWidget(maximumLabel, 1, 0);
+ controlsLayout->addWidget(valueLabel, 2, 0);
+ controlsLayout->addWidget(minimumSpinBox, 0, 1);
+ controlsLayout->addWidget(maximumSpinBox, 1, 1);
+ controlsLayout->addWidget(valueSpinBox, 2, 1);
+ controlsLayout->addWidget(invertedAppearance, 0, 2);
+ controlsLayout->addWidget(invertedKeyBindings, 1, 2);
+ controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3);
+ controlsGroup->setLayout(controlsLayout);
+}
+//! [8]
diff --git a/examples/widgets/sliders/window.h b/examples/widgets/sliders/window.h
new file mode 100644
index 0000000000..3931d18ac2
--- /dev/null
+++ b/examples/widgets/sliders/window.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QGroupBox;
+class QLabel;
+class QSpinBox;
+class QStackedWidget;
+QT_END_NAMESPACE
+class SlidersGroup;
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+private:
+ void createControls(const QString &title);
+
+ SlidersGroup *horizontalSliders;
+ SlidersGroup *verticalSliders;
+ QStackedWidget *stackedWidget;
+
+ QGroupBox *controlsGroup;
+ QLabel *minimumLabel;
+ QLabel *maximumLabel;
+ QLabel *valueLabel;
+ QCheckBox *invertedAppearance;
+ QCheckBox *invertedKeyBindings;
+ QSpinBox *minimumSpinBox;
+ QSpinBox *maximumSpinBox;
+ QSpinBox *valueSpinBox;
+ QComboBox *orientationCombo;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/softkeys/main.cpp b/examples/widgets/softkeys/main.cpp
new file mode 100644
index 0000000000..5678eb37ed
--- /dev/null
+++ b/examples/widgets/softkeys/main.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "softkeys.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mw;
+ mw.showMaximized();
+ return app.exec();
+}
diff --git a/examples/widgets/softkeys/softkeys.cpp b/examples/widgets/softkeys/softkeys.cpp
new file mode 100644
index 0000000000..d3be9c6e7b
--- /dev/null
+++ b/examples/widgets/softkeys/softkeys.cpp
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 "softkeys.h"
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ central = new QWidget(this);
+ central->setContextMenuPolicy(Qt::NoContextMenu); // explicitly forbid usage of context menu so actions item is not shown menu
+ setCentralWidget(central);
+
+ // Create text editor and set softkeys to it
+ textEditor= new QTextEdit(tr("Navigate in UI to see context sensitive softkeys in action"), this);
+ QAction* clear = new QAction(tr("Clear"), this);
+ clear->setSoftKeyRole(QAction::NegativeSoftKey);
+
+ textEditor->addAction(clear);
+
+ ok = new QAction(tr("Ok"), this);
+ ok->setSoftKeyRole(QAction::PositiveSoftKey);
+ connect(ok, SIGNAL(triggered()), this, SLOT(okPressed()));
+
+ cancel = new QAction(tr("Cancel"), this);
+ cancel->setSoftKeyRole(QAction::NegativeSoftKey);
+ connect(cancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
+
+ infoLabel = new QLabel(tr(""), this);
+ infoLabel->setContextMenuPolicy(Qt::NoContextMenu);
+
+ toggleButton = new QPushButton(tr("Custom"), this);
+ toggleButton->setContextMenuPolicy(Qt::NoContextMenu);
+ toggleButton->setCheckable(true);
+
+ modeButton = new QPushButton(tr("Loop SK window type"), this);
+ modeButton->setContextMenuPolicy(Qt::NoContextMenu);
+
+ modeLabel = new QLabel(tr("Normal maximized"), this);
+ modeLabel->setContextMenuPolicy(Qt::NoContextMenu);
+
+ pushButton = new QPushButton(tr("File Dialog"), this);
+ pushButton->setContextMenuPolicy(Qt::NoContextMenu);
+
+ QComboBox* comboBox = new QComboBox(this);
+ comboBox->setContextMenuPolicy(Qt::NoContextMenu);
+ comboBox->insertItems(0, QStringList()
+ << QApplication::translate("MainWindow", "Selection1", 0, QApplication::UnicodeUTF8)
+ << QApplication::translate("MainWindow", "Selection2", 0, QApplication::UnicodeUTF8)
+ << QApplication::translate("MainWindow", "Selection3", 0, QApplication::UnicodeUTF8)
+ );
+
+ layout = new QGridLayout;
+ layout->addWidget(textEditor, 0, 0, 1, 2);
+ layout->addWidget(infoLabel, 1, 0, 1, 2);
+ layout->addWidget(toggleButton, 2, 0);
+ layout->addWidget(pushButton, 2, 1);
+ layout->addWidget(comboBox, 3, 0, 1, 2);
+ layout->addWidget(modeButton, 4, 0, 1, 2);
+ layout->addWidget(modeLabel, 5, 0, 1, 2);
+ central->setLayout(layout);
+
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ exit = new QAction(tr("&Exit"), this);
+ fileMenu->addAction(exit);
+
+ connect(clear, SIGNAL(triggered()), this, SLOT(clearTextEditor()));
+ connect(pushButton, SIGNAL(clicked()), this, SLOT(openDialog()));
+ connect(exit, SIGNAL(triggered()), this, SLOT(exitApplication()));
+ connect(toggleButton, SIGNAL(clicked()), this, SLOT(setCustomSoftKeys()));
+ connect(modeButton, SIGNAL(clicked()), this, SLOT(setMode()));
+ pushButton->setFocus();
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::clearTextEditor()
+{
+ textEditor->setText(tr(""));
+}
+
+void MainWindow::openDialog()
+{
+ QFileDialog::getOpenFileName(this);
+}
+
+void MainWindow::addSoftKeys()
+{
+ addAction(ok);
+ addAction(cancel);
+}
+
+void MainWindow::setCustomSoftKeys()
+{
+ if (toggleButton->isChecked()) {
+ infoLabel->setText(tr("Custom softkeys set"));
+ addSoftKeys();
+ }
+ else {
+ infoLabel->setText(tr("Custom softkeys removed"));
+ removeAction(ok);
+ removeAction(cancel);
+ }
+}
+
+void MainWindow::setMode()
+{
+ if(isMaximized()) {
+ showFullScreen();
+ modeLabel->setText(tr("Normal Fullscreen"));
+ } else {
+ Qt::WindowFlags flags = windowFlags();
+ if(flags & Qt::WindowSoftkeysRespondHint) {
+ flags |= Qt::WindowSoftkeysVisibleHint;
+ flags &= ~Qt::WindowSoftkeysRespondHint;
+ setWindowFlags(flags); // Hides visible window
+ showFullScreen();
+ modeLabel->setText(tr("Fullscreen with softkeys"));
+ } else if(flags & Qt::WindowSoftkeysVisibleHint) {
+ flags &= ~Qt::WindowSoftkeysVisibleHint;
+ flags &= ~Qt::WindowSoftkeysRespondHint;
+ setWindowFlags(flags); // Hides visible window
+ showMaximized();
+ modeLabel->setText(tr("Normal Maximized"));
+ } else {
+ flags &= ~Qt::WindowSoftkeysVisibleHint;
+ flags |= Qt::WindowSoftkeysRespondHint;
+ setWindowFlags(flags); // Hides visible window
+ showFullScreen();
+ modeLabel->setText(tr("Fullscreen with SK respond"));
+ }
+ }
+}
+
+void MainWindow::exitApplication()
+{
+ qApp->exit();
+}
+
+void MainWindow::okPressed()
+{
+ infoLabel->setText(tr("OK pressed"));
+}
+
+void MainWindow::cancelPressed()
+{
+ infoLabel->setText(tr("Cancel pressed"));
+}
+
+
diff --git a/examples/widgets/softkeys/softkeys.h b/examples/widgets/softkeys/softkeys.h
new file mode 100644
index 0000000000..5427e1020f
--- /dev/null
+++ b/examples/widgets/softkeys/softkeys.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SOFTKEYS_H
+#define SOFTKEYS_H
+
+#include <QtGui>
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+public:
+
+private slots:
+ void clearTextEditor();
+ void openDialog();
+ void addSoftKeys();
+ void exitApplication();
+ void okPressed();
+ void cancelPressed();
+ void setCustomSoftKeys();
+ void setMode();
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+private:
+ QGridLayout *layout;
+ QWidget *central;
+ QTextEdit *textEditor;
+ QLabel *infoLabel;
+ QPushButton *toggleButton;
+ QPushButton *pushButton;
+ QPushButton *modeButton;
+ QLabel *modeLabel;
+ QMenu *fileMenu;
+ QAction *addSoftKeysAct;
+ QAction *exit;
+ QAction *ok;
+ QAction *cancel;
+};
+
+//! [0]
+class SoftKey : public QWidget
+{
+ Q_OBJECT
+public:
+ SoftKey(QWidget *parent = 0);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/softkeys/softkeys.pro b/examples/widgets/softkeys/softkeys.pro
new file mode 100644
index 0000000000..14a899c803
--- /dev/null
+++ b/examples/widgets/softkeys/softkeys.pro
@@ -0,0 +1,15 @@
+HEADERS = softkeys.h
+SOURCES += \
+ main.cpp \
+ softkeys.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/softkeys
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS softkeys.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/softkeys
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000CF6B
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/spinboxes/main.cpp b/examples/widgets/spinboxes/main.cpp
new file mode 100644
index 0000000000..f2079f511b
--- /dev/null
+++ b/examples/widgets/spinboxes/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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.pro b/examples/widgets/spinboxes/spinboxes.pro
new file mode 100644
index 0000000000..cef0671362
--- /dev/null
+++ b/examples/widgets/spinboxes/spinboxes.pro
@@ -0,0 +1,11 @@
+HEADERS = window.h
+SOURCES = main.cpp \
+ window.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/spinboxes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS spinboxes.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/spinboxes
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/spinboxes/window.cpp b/examples/widgets/spinboxes/window.cpp
new file mode 100644
index 0000000000..095ff5cf79
--- /dev/null
+++ b/examples/widgets/spinboxes/window.cpp
@@ -0,0 +1,251 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "window.h"
+
+//! [0]
+Window::Window()
+{
+ createSpinBoxes();
+ createDateTimeEdits();
+ createDoubleSpinBoxes();
+
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(spinBoxesGroup);
+ layout->addWidget(editsGroup);
+ layout->addWidget(doubleSpinBoxesGroup);
+ setLayout(layout);
+
+ setWindowTitle(tr("Spin Boxes"));
+}
+//! [0]
+
+//! [1]
+void Window::createSpinBoxes()
+{
+ spinBoxesGroup = new QGroupBox(tr("Spinboxes"));
+
+ QLabel *integerLabel = new QLabel(tr("Enter a value between "
+ "%1 and %2:").arg(-20).arg(20));
+ QSpinBox *integerSpinBox = new QSpinBox;
+ integerSpinBox->setRange(-20, 20);
+ integerSpinBox->setSingleStep(1);
+ integerSpinBox->setValue(0);
+//! [1]
+
+//! [2]
+ QLabel *zoomLabel = new QLabel(tr("Enter a zoom value between "
+ "%1 and %2:").arg(0).arg(1000));
+//! [3]
+ QSpinBox *zoomSpinBox = new QSpinBox;
+ zoomSpinBox->setRange(0, 1000);
+ zoomSpinBox->setSingleStep(10);
+ zoomSpinBox->setSuffix("%");
+ zoomSpinBox->setSpecialValueText(tr("Automatic"));
+ zoomSpinBox->setValue(100);
+//! [2] //! [3]
+
+//! [4]
+ QLabel *priceLabel = new QLabel(tr("Enter a price between "
+ "%1 and %2:").arg(0).arg(999));
+ QSpinBox *priceSpinBox = new QSpinBox;
+ priceSpinBox->setRange(0, 999);
+ priceSpinBox->setSingleStep(1);
+ priceSpinBox->setPrefix("$");
+ priceSpinBox->setValue(99);
+//! [4] //! [5]
+
+ QVBoxLayout *spinBoxLayout = new QVBoxLayout;
+ spinBoxLayout->addWidget(integerLabel);
+ spinBoxLayout->addWidget(integerSpinBox);
+ spinBoxLayout->addWidget(zoomLabel);
+ spinBoxLayout->addWidget(zoomSpinBox);
+ spinBoxLayout->addWidget(priceLabel);
+ spinBoxLayout->addWidget(priceSpinBox);
+ spinBoxesGroup->setLayout(spinBoxLayout);
+}
+//! [5]
+
+//! [6]
+void Window::createDateTimeEdits()
+{
+ editsGroup = new QGroupBox(tr("Date and time spin boxes"));
+
+ QLabel *dateLabel = new QLabel;
+ QDateEdit *dateEdit = new QDateEdit(QDate::currentDate());
+ dateEdit->setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31));
+ dateLabel->setText(tr("Appointment date (between %0 and %1):")
+ .arg(dateEdit->minimumDate().toString(Qt::ISODate))
+ .arg(dateEdit->maximumDate().toString(Qt::ISODate)));
+//! [6]
+
+//! [7]
+ QLabel *timeLabel = new QLabel;
+ QTimeEdit *timeEdit = new QTimeEdit(QTime::currentTime());
+ timeEdit->setTimeRange(QTime(9, 0, 0, 0), QTime(16, 30, 0, 0));
+ timeLabel->setText(tr("Appointment time (between %0 and %1):")
+ .arg(timeEdit->minimumTime().toString(Qt::ISODate))
+ .arg(timeEdit->maximumTime().toString(Qt::ISODate)));
+//! [7]
+
+//! [8]
+ meetingLabel = new QLabel;
+ meetingEdit = new QDateTimeEdit(QDateTime::currentDateTime());
+//! [8]
+
+//! [9]
+ QLabel *formatLabel = new QLabel(tr("Format string for the meeting date "
+ "and time:"));
+ QComboBox *formatComboBox = new QComboBox;
+ formatComboBox->addItem("yyyy-MM-dd hh:mm:ss (zzz 'ms')");
+ formatComboBox->addItem("hh:mm:ss MM/dd/yyyy");
+ formatComboBox->addItem("hh:mm:ss dd/MM/yyyy");
+ formatComboBox->addItem("hh:mm:ss");
+ formatComboBox->addItem("hh:mm ap");
+//! [9] //! [10]
+
+ connect(formatComboBox, SIGNAL(activated(QString)),
+ this, SLOT(setFormatString(QString)));
+//! [10]
+
+ setFormatString(formatComboBox->currentText());
+
+//! [11]
+ QVBoxLayout *editsLayout = new QVBoxLayout;
+ editsLayout->addWidget(dateLabel);
+ editsLayout->addWidget(dateEdit);
+ editsLayout->addWidget(timeLabel);
+ editsLayout->addWidget(timeEdit);
+ editsLayout->addWidget(meetingLabel);
+ editsLayout->addWidget(meetingEdit);
+ editsLayout->addWidget(formatLabel);
+ editsLayout->addWidget(formatComboBox);
+ editsGroup->setLayout(editsLayout);
+}
+//! [11]
+
+//! [12]
+void Window::setFormatString(const QString &formatString)
+{
+ meetingEdit->setDisplayFormat(formatString);
+//! [12] //! [13]
+ if (meetingEdit->displayedSections() & QDateTimeEdit::DateSections_Mask) {
+ meetingEdit->setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30));
+ meetingLabel->setText(tr("Meeting date (between %0 and %1):")
+ .arg(meetingEdit->minimumDate().toString(Qt::ISODate))
+ .arg(meetingEdit->maximumDate().toString(Qt::ISODate)));
+ } else {
+ meetingEdit->setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0));
+ meetingLabel->setText(tr("Meeting time (between %0 and %1):")
+ .arg(meetingEdit->minimumTime().toString(Qt::ISODate))
+ .arg(meetingEdit->maximumTime().toString(Qt::ISODate)));
+ }
+}
+//! [13]
+
+//! [14]
+void Window::createDoubleSpinBoxes()
+{
+ doubleSpinBoxesGroup = new QGroupBox(tr("Double precision spinboxes"));
+
+ QLabel *precisionLabel = new QLabel(tr("Number of decimal places "
+ "to show:"));
+ QSpinBox *precisionSpinBox = new QSpinBox;
+ precisionSpinBox->setRange(0, 100);
+ precisionSpinBox->setValue(2);
+//! [14]
+
+//! [15]
+ QLabel *doubleLabel = new QLabel(tr("Enter a value between "
+ "%1 and %2:").arg(-20).arg(20));
+ doubleSpinBox = new QDoubleSpinBox;
+ doubleSpinBox->setRange(-20.0, 20.0);
+ doubleSpinBox->setSingleStep(1.0);
+ doubleSpinBox->setValue(0.0);
+//! [15]
+
+//! [16]
+ QLabel *scaleLabel = new QLabel(tr("Enter a scale factor between "
+ "%1 and %2:").arg(0).arg(1000.0));
+ scaleSpinBox = new QDoubleSpinBox;
+ scaleSpinBox->setRange(0.0, 1000.0);
+ scaleSpinBox->setSingleStep(10.0);
+ scaleSpinBox->setSuffix("%");
+ scaleSpinBox->setSpecialValueText(tr("No scaling"));
+ scaleSpinBox->setValue(100.0);
+//! [16]
+
+//! [17]
+ QLabel *priceLabel = new QLabel(tr("Enter a price between "
+ "%1 and %2:").arg(0).arg(1000));
+ priceSpinBox = new QDoubleSpinBox;
+ priceSpinBox->setRange(0.0, 1000.0);
+ priceSpinBox->setSingleStep(1.0);
+ priceSpinBox->setPrefix("$");
+ priceSpinBox->setValue(99.99);
+
+ connect(precisionSpinBox, SIGNAL(valueChanged(int)),
+//! [17]
+ this, SLOT(changePrecision(int)));
+
+//! [18]
+ QVBoxLayout *spinBoxLayout = new QVBoxLayout;
+ spinBoxLayout->addWidget(precisionLabel);
+ spinBoxLayout->addWidget(precisionSpinBox);
+ spinBoxLayout->addWidget(doubleLabel);
+ spinBoxLayout->addWidget(doubleSpinBox);
+ spinBoxLayout->addWidget(scaleLabel);
+ spinBoxLayout->addWidget(scaleSpinBox);
+ spinBoxLayout->addWidget(priceLabel);
+ spinBoxLayout->addWidget(priceSpinBox);
+ doubleSpinBoxesGroup->setLayout(spinBoxLayout);
+}
+//! [18]
+
+//! [19]
+void Window::changePrecision(int decimals)
+{
+ doubleSpinBox->setDecimals(decimals);
+ scaleSpinBox->setDecimals(decimals);
+ priceSpinBox->setDecimals(decimals);
+}
+//! [19]
diff --git a/examples/widgets/spinboxes/window.h b/examples/widgets/spinboxes/window.h
new file mode 100644
index 0000000000..41d75916eb
--- /dev/null
+++ b/examples/widgets/spinboxes/window.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QDateTimeEdit;
+class QDoubleSpinBox;
+class QGroupBox;
+class QLabel;
+QT_END_NAMESPACE
+
+//! [0]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window();
+
+public slots:
+ void changePrecision(int decimals);
+ void setFormatString(const QString &formatString);
+
+private:
+ void createSpinBoxes();
+ void createDateTimeEdits();
+ void createDoubleSpinBoxes();
+
+ QDateTimeEdit *meetingEdit;
+ QDoubleSpinBox *doubleSpinBox;
+ QDoubleSpinBox *priceSpinBox;
+ QDoubleSpinBox *scaleSpinBox;
+ QGroupBox *spinBoxesGroup;
+ QGroupBox *editsGroup;
+ QGroupBox *doubleSpinBoxesGroup;
+ QLabel *meetingLabel;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/styles/images/woodbackground.png b/examples/widgets/styles/images/woodbackground.png
new file mode 100644
index 0000000000..8be3366bb4
--- /dev/null
+++ b/examples/widgets/styles/images/woodbackground.png
Binary files differ
diff --git a/examples/widgets/styles/images/woodbutton.png b/examples/widgets/styles/images/woodbutton.png
new file mode 100644
index 0000000000..adb59ef633
--- /dev/null
+++ b/examples/widgets/styles/images/woodbutton.png
Binary files differ
diff --git a/examples/widgets/styles/main.cpp b/examples/widgets/styles/main.cpp
new file mode 100644
index 0000000000..3d6d29c474
--- /dev/null
+++ b/examples/widgets/styles/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "widgetgallery.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(styles);
+
+ QApplication app(argc, argv);
+ WidgetGallery gallery;
+ gallery.show();
+ return app.exec();
+}
diff --git a/examples/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/styles/norwegianwoodstyle.cpp
new file mode 100644
index 0000000000..9fd0fed041
--- /dev/null
+++ b/examples/widgets/styles/norwegianwoodstyle.cpp
@@ -0,0 +1,330 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "norwegianwoodstyle.h"
+
+//! [0]
+void NorwegianWoodStyle::polish(QPalette &palette)
+{
+ QColor brown(212, 140, 95);
+ QColor beige(236, 182, 120);
+ QColor slightlyOpaqueBlack(0, 0, 0, 63);
+
+ QPixmap backgroundImage(":/images/woodbackground.png");
+ QPixmap buttonImage(":/images/woodbutton.png");
+ QPixmap midImage = buttonImage;
+
+ QPainter painter;
+ painter.begin(&midImage);
+ painter.setPen(Qt::NoPen);
+ painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
+ painter.end();
+//! [0]
+
+//! [1]
+ palette = QPalette(brown);
+
+ palette.setBrush(QPalette::BrightText, Qt::white);
+ palette.setBrush(QPalette::Base, beige);
+ palette.setBrush(QPalette::Highlight, Qt::darkGreen);
+ setTexture(palette, QPalette::Button, buttonImage);
+ setTexture(palette, QPalette::Mid, midImage);
+ setTexture(palette, QPalette::Window, backgroundImage);
+
+ QBrush brush = palette.background();
+ brush.setColor(brush.color().dark());
+
+ palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Text, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Button, brush);
+ palette.setBrush(QPalette::Disabled, QPalette::Mid, brush);
+}
+//! [1]
+
+//! [3]
+void NorwegianWoodStyle::polish(QWidget *widget)
+//! [3] //! [4]
+{
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QComboBox *>(widget))
+ widget->setAttribute(Qt::WA_Hover, true);
+}
+//! [4]
+
+//! [5]
+void NorwegianWoodStyle::unpolish(QWidget *widget)
+//! [5] //! [6]
+{
+ if (qobject_cast<QPushButton *>(widget)
+ || qobject_cast<QComboBox *>(widget))
+ widget->setAttribute(Qt::WA_Hover, false);
+}
+//! [6]
+
+//! [7]
+int NorwegianWoodStyle::pixelMetric(PixelMetric metric,
+//! [7] //! [8]
+ const QStyleOption *option,
+ const QWidget *widget) const
+{
+ switch (metric) {
+ case PM_ComboBoxFrameWidth:
+ return 8;
+ case PM_ScrollBarExtent:
+ return QMotifStyle::pixelMetric(metric, option, widget) + 4;
+ default:
+ return QMotifStyle::pixelMetric(metric, option, widget);
+ }
+}
+//! [8]
+
+//! [9]
+int NorwegianWoodStyle::styleHint(StyleHint hint, const QStyleOption *option,
+//! [9] //! [10]
+ const QWidget *widget,
+ QStyleHintReturn *returnData) const
+{
+ switch (hint) {
+ case SH_DitherDisabledText:
+ return int(false);
+ case SH_EtchDisabledText:
+ return int(true);
+ default:
+ return QMotifStyle::styleHint(hint, option, widget, returnData);
+ }
+}
+//! [10]
+
+//! [11]
+void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element,
+//! [11] //! [12]
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const
+{
+ switch (element) {
+ case PE_PanelButtonCommand:
+ {
+ int delta = (option->state & State_MouseOver) ? 64 : 0;
+ QColor slightlyOpaqueBlack(0, 0, 0, 63);
+ QColor semiTransparentWhite(255, 255, 255, 127 + delta);
+ QColor semiTransparentBlack(0, 0, 0, 127 - delta);
+
+ int x, y, width, height;
+ option->rect.getRect(&x, &y, &width, &height);
+//! [12]
+
+//! [13]
+ QPainterPath roundRect = roundRectPath(option->rect);
+//! [13] //! [14]
+ int radius = qMin(width, height) / 2;
+//! [14]
+
+//! [15]
+ QBrush brush;
+//! [15] //! [16]
+ bool darker;
+
+ const QStyleOptionButton *buttonOption =
+ qstyleoption_cast<const QStyleOptionButton *>(option);
+ if (buttonOption
+ && (buttonOption->features & QStyleOptionButton::Flat)) {
+ brush = option->palette.background();
+ darker = (option->state & (State_Sunken | State_On));
+ } else {
+ if (option->state & (State_Sunken | State_On)) {
+ brush = option->palette.mid();
+ darker = !(option->state & State_Sunken);
+ } else {
+ brush = option->palette.button();
+ darker = false;
+//! [16] //! [17]
+ }
+//! [17] //! [18]
+ }
+//! [18]
+
+//! [19]
+ painter->save();
+//! [19] //! [20]
+ painter->setRenderHint(QPainter::Antialiasing, true);
+//! [20] //! [21]
+ painter->fillPath(roundRect, brush);
+//! [21] //! [22]
+ if (darker)
+//! [22] //! [23]
+ painter->fillPath(roundRect, slightlyOpaqueBlack);
+//! [23]
+
+//! [24]
+ int penWidth;
+//! [24] //! [25]
+ if (radius < 10)
+ penWidth = 3;
+ else if (radius < 20)
+ penWidth = 5;
+ else
+ penWidth = 7;
+
+ QPen topPen(semiTransparentWhite, penWidth);
+ QPen bottomPen(semiTransparentBlack, penWidth);
+
+ if (option->state & (State_Sunken | State_On))
+ qSwap(topPen, bottomPen);
+//! [25]
+
+//! [26]
+ int x1 = x;
+ int x2 = x + radius;
+ int x3 = x + width - radius;
+ int x4 = x + width;
+
+ if (option->direction == Qt::RightToLeft) {
+ qSwap(x1, x4);
+ qSwap(x2, x3);
+ }
+
+ QPolygon topHalf;
+ topHalf << QPoint(x1, y)
+ << QPoint(x4, y)
+ << QPoint(x3, y + radius)
+ << QPoint(x2, y + height - radius)
+ << QPoint(x1, y + height);
+
+ painter->setClipPath(roundRect);
+ painter->setClipRegion(topHalf, Qt::IntersectClip);
+ painter->setPen(topPen);
+ painter->drawPath(roundRect);
+//! [26] //! [32]
+
+ QPolygon bottomHalf = topHalf;
+ bottomHalf[0] = QPoint(x4, y + height);
+
+ painter->setClipPath(roundRect);
+ painter->setClipRegion(bottomHalf, Qt::IntersectClip);
+ painter->setPen(bottomPen);
+ painter->drawPath(roundRect);
+
+ painter->setPen(option->palette.foreground().color());
+ painter->setClipping(false);
+ painter->drawPath(roundRect);
+
+ painter->restore();
+ }
+ break;
+//! [32] //! [33]
+ default:
+//! [33] //! [34]
+ QMotifStyle::drawPrimitive(element, option, painter, widget);
+ }
+}
+//! [34]
+
+//! [35]
+void NorwegianWoodStyle::drawControl(ControlElement element,
+//! [35] //! [36]
+ const QStyleOption *option,
+ QPainter *painter,
+ const QWidget *widget) const
+{
+ switch (element) {
+ case CE_PushButtonLabel:
+ {
+ QStyleOptionButton myButtonOption;
+ const QStyleOptionButton *buttonOption =
+ qstyleoption_cast<const QStyleOptionButton *>(option);
+ if (buttonOption) {
+ myButtonOption = *buttonOption;
+ if (myButtonOption.palette.currentColorGroup()
+ != QPalette::Disabled) {
+ if (myButtonOption.state & (State_Sunken | State_On)) {
+ myButtonOption.palette.setBrush(QPalette::ButtonText,
+ myButtonOption.palette.brightText());
+ }
+ }
+ }
+ QMotifStyle::drawControl(element, &myButtonOption, painter, widget);
+ }
+ break;
+ default:
+ QMotifStyle::drawControl(element, option, painter, widget);
+ }
+}
+//! [36]
+
+//! [37]
+void NorwegianWoodStyle::setTexture(QPalette &palette, QPalette::ColorRole role,
+//! [37] //! [38]
+ const QPixmap &pixmap)
+{
+ for (int i = 0; i < QPalette::NColorGroups; ++i) {
+ QColor color = palette.brush(QPalette::ColorGroup(i), role).color();
+ palette.setBrush(QPalette::ColorGroup(i), role, QBrush(color, pixmap));
+ }
+}
+//! [38]
+
+//! [39]
+QPainterPath NorwegianWoodStyle::roundRectPath(const QRect &rect)
+//! [39] //! [40]
+{
+ int radius = qMin(rect.width(), rect.height()) / 2;
+ int diam = 2 * radius;
+
+ int x1, y1, x2, y2;
+ rect.getCoords(&x1, &y1, &x2, &y2);
+
+ QPainterPath path;
+ path.moveTo(x2, y1 + radius);
+ path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0);
+ path.lineTo(x1 + radius, y1);
+ path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0);
+ path.lineTo(x1, y2 - radius);
+ path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0);
+ path.lineTo(x1 + radius, y2);
+ path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0);
+ path.closeSubpath();
+ return path;
+}
+//! [40]
diff --git a/examples/widgets/styles/norwegianwoodstyle.h b/examples/widgets/styles/norwegianwoodstyle.h
new file mode 100644
index 0000000000..cc77a406d6
--- /dev/null
+++ b/examples/widgets/styles/norwegianwoodstyle.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef NORWEGIANWOODSTYLE_H
+#define NORWEGIANWOODSTYLE_H
+
+#include <QMotifStyle>
+#include <QPalette>
+
+QT_BEGIN_NAMESPACE
+class QPainterPath;
+QT_END_NAMESPACE
+
+//! [0]
+class NorwegianWoodStyle : public QMotifStyle
+{
+ Q_OBJECT
+
+public:
+ NorwegianWoodStyle() {}
+
+ void polish(QPalette &palette);
+ void polish(QWidget *widget);
+ void unpolish(QWidget *widget);
+ int pixelMetric(PixelMetric metric, const QStyleOption *option,
+ const QWidget *widget) const;
+ int styleHint(StyleHint hint, const QStyleOption *option,
+ const QWidget *widget, QStyleHintReturn *returnData) const;
+ void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const;
+ void drawControl(ControlElement control, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const;
+
+private:
+ static void setTexture(QPalette &palette, QPalette::ColorRole role,
+ const QPixmap &pixmap);
+ static QPainterPath roundRectPath(const QRect &rect);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/styles/styles.pro b/examples/widgets/styles/styles.pro
new file mode 100644
index 0000000000..7920b89356
--- /dev/null
+++ b/examples/widgets/styles/styles.pro
@@ -0,0 +1,16 @@
+HEADERS = norwegianwoodstyle.h \
+ widgetgallery.h
+SOURCES = main.cpp \
+ norwegianwoodstyle.cpp \
+ widgetgallery.cpp
+RESOURCES = styles.qrc
+
+REQUIRES += "contains(styles, motif)"
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/styles
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS styles.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/styles
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/styles/styles.qrc b/examples/widgets/styles/styles.qrc
new file mode 100644
index 0000000000..4fdad8d914
--- /dev/null
+++ b/examples/widgets/styles/styles.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/woodbutton.png</file>
+ <file>images/woodbackground.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/styles/widgetgallery.cpp b/examples/widgets/styles/widgetgallery.cpp
new file mode 100644
index 0000000000..2867159895
--- /dev/null
+++ b/examples/widgets/styles/widgetgallery.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "norwegianwoodstyle.h"
+#include "widgetgallery.h"
+
+//! [0]
+WidgetGallery::WidgetGallery(QWidget *parent)
+ : QDialog(parent)
+{
+ originalPalette = QApplication::palette();
+
+ styleComboBox = new QComboBox;
+ styleComboBox->addItem("NorwegianWood");
+ styleComboBox->addItems(QStyleFactory::keys());
+
+ styleLabel = new QLabel(tr("&Style:"));
+ styleLabel->setBuddy(styleComboBox);
+
+ useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette"));
+ useStylePaletteCheckBox->setChecked(true);
+
+ disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets"));
+
+ createTopLeftGroupBox();
+ createTopRightGroupBox();
+ createBottomLeftTabWidget();
+ createBottomRightGroupBox();
+ createProgressBar();
+//! [0]
+
+//! [1]
+ connect(styleComboBox, SIGNAL(activated(QString)),
+//! [1] //! [2]
+ this, SLOT(changeStyle(QString)));
+ connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)),
+ this, SLOT(changePalette()));
+ connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
+ topLeftGroupBox, SLOT(setDisabled(bool)));
+ connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
+ topRightGroupBox, SLOT(setDisabled(bool)));
+ connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
+ bottomLeftTabWidget, SLOT(setDisabled(bool)));
+ connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
+ bottomRightGroupBox, SLOT(setDisabled(bool)));
+//! [2]
+
+//! [3]
+ QHBoxLayout *topLayout = new QHBoxLayout;
+//! [3] //! [4]
+ topLayout->addWidget(styleLabel);
+ topLayout->addWidget(styleComboBox);
+ topLayout->addStretch(1);
+ topLayout->addWidget(useStylePaletteCheckBox);
+ topLayout->addWidget(disableWidgetsCheckBox);
+
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addLayout(topLayout, 0, 0, 1, 2);
+ mainLayout->addWidget(topLeftGroupBox, 1, 0);
+ mainLayout->addWidget(topRightGroupBox, 1, 1);
+ mainLayout->addWidget(bottomLeftTabWidget, 2, 0);
+ mainLayout->addWidget(bottomRightGroupBox, 2, 1);
+ mainLayout->addWidget(progressBar, 3, 0, 1, 2);
+ mainLayout->setRowStretch(1, 1);
+ mainLayout->setRowStretch(2, 1);
+ mainLayout->setColumnStretch(0, 1);
+ mainLayout->setColumnStretch(1, 1);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Styles"));
+ changeStyle("NorwegianWood");
+}
+//! [4]
+
+//! [5]
+void WidgetGallery::changeStyle(const QString &styleName)
+//! [5] //! [6]
+{
+ if (styleName == "NorwegianWood") {
+ QApplication::setStyle(new NorwegianWoodStyle);
+ } else {
+ QApplication::setStyle(QStyleFactory::create(styleName));
+ }
+ changePalette();
+}
+//! [6]
+
+//! [7]
+void WidgetGallery::changePalette()
+//! [7] //! [8]
+{
+ if (useStylePaletteCheckBox->isChecked())
+ QApplication::setPalette(QApplication::style()->standardPalette());
+ else
+ QApplication::setPalette(originalPalette);
+}
+//! [8]
+
+//! [9]
+void WidgetGallery::advanceProgressBar()
+//! [9] //! [10]
+{
+ int curVal = progressBar->value();
+ int maxVal = progressBar->maximum();
+ progressBar->setValue(curVal + (maxVal - curVal) / 100);
+}
+//! [10]
+
+//! [11]
+void WidgetGallery::createTopLeftGroupBox()
+//! [11] //! [12]
+{
+ topLeftGroupBox = new QGroupBox(tr("Group 1"));
+
+ radioButton1 = new QRadioButton(tr("Radio button 1"));
+ radioButton2 = new QRadioButton(tr("Radio button 2"));
+ radioButton3 = new QRadioButton(tr("Radio button 3"));
+ radioButton1->setChecked(true);
+
+ checkBox = new QCheckBox(tr("Tri-state check box"));
+ checkBox->setTristate(true);
+ checkBox->setCheckState(Qt::PartiallyChecked);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(radioButton1);
+ layout->addWidget(radioButton2);
+ layout->addWidget(radioButton3);
+ layout->addWidget(checkBox);
+ layout->addStretch(1);
+ topLeftGroupBox->setLayout(layout);
+}
+//! [12]
+
+void WidgetGallery::createTopRightGroupBox()
+{
+ topRightGroupBox = new QGroupBox(tr("Group 2"));
+
+ defaultPushButton = new QPushButton(tr("Default Push Button"));
+ defaultPushButton->setDefault(true);
+
+ togglePushButton = new QPushButton(tr("Toggle Push Button"));
+ togglePushButton->setCheckable(true);
+ togglePushButton->setChecked(true);
+
+ flatPushButton = new QPushButton(tr("Flat Push Button"));
+ flatPushButton->setFlat(true);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(defaultPushButton);
+ layout->addWidget(togglePushButton);
+ layout->addWidget(flatPushButton);
+ layout->addStretch(1);
+ topRightGroupBox->setLayout(layout);
+}
+
+void WidgetGallery::createBottomLeftTabWidget()
+{
+ bottomLeftTabWidget = new QTabWidget;
+ bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred,
+ QSizePolicy::Ignored);
+
+ QWidget *tab1 = new QWidget;
+ tableWidget = new QTableWidget(10, 10);
+
+ QHBoxLayout *tab1hbox = new QHBoxLayout;
+ tab1hbox->setMargin(5);
+ tab1hbox->addWidget(tableWidget);
+ tab1->setLayout(tab1hbox);
+
+ QWidget *tab2 = new QWidget;
+ textEdit = new QTextEdit;
+
+ textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n"
+ "How I wonder what you are.\n"
+ "Up above the world so high,\n"
+ "Like a diamond in the sky.\n"
+ "Twinkle, twinkle, little star,\n"
+ "How I wonder what you are!\n"));
+
+ QHBoxLayout *tab2hbox = new QHBoxLayout;
+ tab2hbox->setMargin(5);
+ tab2hbox->addWidget(textEdit);
+ tab2->setLayout(tab2hbox);
+
+ bottomLeftTabWidget->addTab(tab1, tr("&Table"));
+ bottomLeftTabWidget->addTab(tab2, tr("Text &Edit"));
+}
+
+void WidgetGallery::createBottomRightGroupBox()
+{
+ bottomRightGroupBox = new QGroupBox(tr("Group 3"));
+ bottomRightGroupBox->setCheckable(true);
+ bottomRightGroupBox->setChecked(true);
+
+ lineEdit = new QLineEdit("s3cRe7");
+ lineEdit->setEchoMode(QLineEdit::Password);
+
+ spinBox = new QSpinBox(bottomRightGroupBox);
+ spinBox->setValue(50);
+
+ dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox);
+ dateTimeEdit->setDateTime(QDateTime::currentDateTime());
+
+ slider = new QSlider(Qt::Horizontal, bottomRightGroupBox);
+ slider->setValue(40);
+
+ scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox);
+ scrollBar->setValue(60);
+
+ dial = new QDial(bottomRightGroupBox);
+ dial->setValue(30);
+ dial->setNotchesVisible(true);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(lineEdit, 0, 0, 1, 2);
+ layout->addWidget(spinBox, 1, 0, 1, 2);
+ layout->addWidget(dateTimeEdit, 2, 0, 1, 2);
+ layout->addWidget(slider, 3, 0);
+ layout->addWidget(scrollBar, 4, 0);
+ layout->addWidget(dial, 3, 1, 2, 1);
+ layout->setRowStretch(5, 1);
+ bottomRightGroupBox->setLayout(layout);
+}
+
+//! [13]
+void WidgetGallery::createProgressBar()
+{
+ progressBar = new QProgressBar;
+ progressBar->setRange(0, 10000);
+ progressBar->setValue(0);
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
+ timer->start(1000);
+}
+//! [13]
diff --git a/examples/widgets/styles/widgetgallery.h b/examples/widgets/styles/widgetgallery.h
new file mode 100644
index 0000000000..31ccc6fb3e
--- /dev/null
+++ b/examples/widgets/styles/widgetgallery.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WIDGETGALLERY_H
+#define WIDGETGALLERY_H
+
+#include <QDialog>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QComboBox;
+class QDateTimeEdit;
+class QDial;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QProgressBar;
+class QPushButton;
+class QRadioButton;
+class QScrollBar;
+class QSlider;
+class QSpinBox;
+class QTabWidget;
+class QTableWidget;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class WidgetGallery : public QDialog
+{
+ Q_OBJECT
+
+public:
+ WidgetGallery(QWidget *parent = 0);
+
+private slots:
+ void changeStyle(const QString &styleName);
+ void changePalette();
+ void advanceProgressBar();
+
+private:
+ void createTopLeftGroupBox();
+ void createTopRightGroupBox();
+ void createBottomLeftTabWidget();
+ void createBottomRightGroupBox();
+ void createProgressBar();
+
+ QPalette originalPalette;
+
+ QLabel *styleLabel;
+ QComboBox *styleComboBox;
+ QCheckBox *useStylePaletteCheckBox;
+ QCheckBox *disableWidgetsCheckBox;
+//! [0]
+
+ QGroupBox *topLeftGroupBox;
+ QRadioButton *radioButton1;
+ QRadioButton *radioButton2;
+ QRadioButton *radioButton3;
+ QCheckBox *checkBox;
+
+ QGroupBox *topRightGroupBox;
+ QPushButton *defaultPushButton;
+ QPushButton *togglePushButton;
+ QPushButton *flatPushButton;
+
+ QTabWidget *bottomLeftTabWidget;
+ QTableWidget *tableWidget;
+ QTextEdit *textEdit;
+
+ QGroupBox *bottomRightGroupBox;
+ QLineEdit *lineEdit;
+ QSpinBox *spinBox;
+ QDateTimeEdit *dateTimeEdit;
+ QSlider *slider;
+ QScrollBar *scrollBar;
+ QDial *dial;
+
+ QProgressBar *progressBar;
+//! [1]
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/stylesheet/images/checkbox_checked.png b/examples/widgets/stylesheet/images/checkbox_checked.png
new file mode 100644
index 0000000000..cbf06f6513
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_checked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_checked_hover.png b/examples/widgets/stylesheet/images/checkbox_checked_hover.png
new file mode 100644
index 0000000000..fb4d4d3fdb
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_checked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_checked_pressed.png b/examples/widgets/stylesheet/images/checkbox_checked_pressed.png
new file mode 100644
index 0000000000..852fcc0306
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_checked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked.png b/examples/widgets/stylesheet/images/checkbox_unchecked.png
new file mode 100644
index 0000000000..5f5465582a
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_unchecked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png b/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png
new file mode 100644
index 0000000000..687364497e
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_unchecked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png b/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png
new file mode 100644
index 0000000000..6a768c44de
--- /dev/null
+++ b/examples/widgets/stylesheet/images/checkbox_unchecked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/down_arrow.png b/examples/widgets/stylesheet/images/down_arrow.png
new file mode 100644
index 0000000000..85004aeaf6
--- /dev/null
+++ b/examples/widgets/stylesheet/images/down_arrow.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/down_arrow_disabled.png b/examples/widgets/stylesheet/images/down_arrow_disabled.png
new file mode 100644
index 0000000000..d9eefed4c8
--- /dev/null
+++ b/examples/widgets/stylesheet/images/down_arrow_disabled.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/frame.png b/examples/widgets/stylesheet/images/frame.png
new file mode 100644
index 0000000000..05a600502e
--- /dev/null
+++ b/examples/widgets/stylesheet/images/frame.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pagefold.png b/examples/widgets/stylesheet/images/pagefold.png
new file mode 100644
index 0000000000..69be8f2a38
--- /dev/null
+++ b/examples/widgets/stylesheet/images/pagefold.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton.png b/examples/widgets/stylesheet/images/pushbutton.png
new file mode 100644
index 0000000000..c7529ba02d
--- /dev/null
+++ b/examples/widgets/stylesheet/images/pushbutton.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton_hover.png b/examples/widgets/stylesheet/images/pushbutton_hover.png
new file mode 100644
index 0000000000..af0ef9d561
--- /dev/null
+++ b/examples/widgets/stylesheet/images/pushbutton_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/pushbutton_pressed.png b/examples/widgets/stylesheet/images/pushbutton_pressed.png
new file mode 100644
index 0000000000..f7381f752a
--- /dev/null
+++ b/examples/widgets/stylesheet/images/pushbutton_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked.png b/examples/widgets/stylesheet/images/radiobutton_checked.png
new file mode 100644
index 0000000000..8ab9157578
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_checked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_hover.png b/examples/widgets/stylesheet/images/radiobutton_checked_hover.png
new file mode 100644
index 0000000000..d68cb009a7
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_checked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png b/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png
new file mode 100644
index 0000000000..e3cd5a59e4
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_checked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked.png b/examples/widgets/stylesheet/images/radiobutton_unchecked.png
new file mode 100644
index 0000000000..321a9a1558
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_unchecked.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png b/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png
new file mode 100644
index 0000000000..666a3b0bdd
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_unchecked_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png b/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
new file mode 100644
index 0000000000..c4b0567aa9
--- /dev/null
+++ b/examples/widgets/stylesheet/images/radiobutton_unchecked_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/sizegrip.png b/examples/widgets/stylesheet/images/sizegrip.png
new file mode 100644
index 0000000000..350583aaac
--- /dev/null
+++ b/examples/widgets/stylesheet/images/sizegrip.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown.png b/examples/widgets/stylesheet/images/spindown.png
new file mode 100644
index 0000000000..7ff3c64926
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spindown.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_hover.png b/examples/widgets/stylesheet/images/spindown_hover.png
new file mode 100644
index 0000000000..1486c4dfe4
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spindown_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_off.png b/examples/widgets/stylesheet/images/spindown_off.png
new file mode 100644
index 0000000000..a90ab3f038
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spindown_off.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spindown_pressed.png b/examples/widgets/stylesheet/images/spindown_pressed.png
new file mode 100644
index 0000000000..f6271cbde2
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spindown_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup.png b/examples/widgets/stylesheet/images/spinup.png
new file mode 100644
index 0000000000..1069dd00df
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spinup.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_hover.png b/examples/widgets/stylesheet/images/spinup_hover.png
new file mode 100644
index 0000000000..884c8d77c5
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spinup_hover.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_off.png b/examples/widgets/stylesheet/images/spinup_off.png
new file mode 100644
index 0000000000..02dad1fb29
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spinup_off.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/spinup_pressed.png b/examples/widgets/stylesheet/images/spinup_pressed.png
new file mode 100644
index 0000000000..b1843e2a1f
--- /dev/null
+++ b/examples/widgets/stylesheet/images/spinup_pressed.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/up_arrow.png b/examples/widgets/stylesheet/images/up_arrow.png
new file mode 100644
index 0000000000..e7f7ddb3a6
--- /dev/null
+++ b/examples/widgets/stylesheet/images/up_arrow.png
Binary files differ
diff --git a/examples/widgets/stylesheet/images/up_arrow_disabled.png b/examples/widgets/stylesheet/images/up_arrow_disabled.png
new file mode 100644
index 0000000000..4d2c27770f
--- /dev/null
+++ b/examples/widgets/stylesheet/images/up_arrow_disabled.png
Binary files differ
diff --git a/examples/widgets/stylesheet/layouts/default.ui b/examples/widgets/stylesheet/layouts/default.ui
new file mode 100644
index 0000000000..431a40956e
--- /dev/null
+++ b/examples/widgets/stylesheet/layouts/default.ui
@@ -0,0 +1,329 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>388</width>
+ <height>413</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="nameLabel" >
+ <property name="text" >
+ <string>&amp;Name:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>nameCombo</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="3" >
+ <widget class="QComboBox" name="nameCombo" >
+ <property name="toolTip" >
+ <string>Specify your name</string>
+ </property>
+ <property name="editable" >
+ <bool>true</bool>
+ </property>
+ <property name="currentIndex" >
+ <number>-1</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Girish</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Jasmin</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Simon</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Zack</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QRadioButton" name="femaleRadioButton" >
+ <property name="toolTip" >
+ <string>Check this if you are female</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Female</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" colspan="4" >
+ <widget class="QCheckBox" name="agreeCheckBox" >
+ <property name="toolTip" >
+ <string>Please read the license before checking this</string>
+ </property>
+ <property name="text" >
+ <string>I &amp;accept the terms and conditions</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QRadioButton" name="maleRadioButton" >
+ <property name="toolTip" >
+ <string>Check this if you are male</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Male</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="genderLabel" >
+ <property name="text" >
+ <string>Gender:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="3" >
+ <widget class="QSpinBox" name="ageSpinBox" >
+ <property name="toolTip" >
+ <string>Specify your age</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your age here</string>
+ </property>
+ <property name="minimum" >
+ <number>12</number>
+ </property>
+ <property name="value" >
+ <number>22</number>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="2" colspan="2" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="ageLabel" >
+ <property name="text" >
+ <string>&amp;Age:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>ageSpinBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="passwordLabel" >
+ <property name="text" >
+ <string>&amp;Password:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>passwordEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="3" >
+ <widget class="QLineEdit" name="passwordEdit" >
+ <property name="toolTip" >
+ <string>Specify your password</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your password here</string>
+ </property>
+ <property name="text" >
+ <string>Password</string>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Profession</string>
+ </property>
+ <property name="buddy" >
+ <cstring>professionList</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="countryLabel" >
+ <property name="text" >
+ <string>&amp;Country</string>
+ </property>
+ <property name="buddy" >
+ <cstring>professionList</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" colspan="3" >
+ <widget class="QListWidget" name="professionList" >
+ <property name="toolTip" >
+ <string>Select your profession</string>
+ </property>
+ <property name="statusTip" >
+ <string>Select your profession</string>
+ </property>
+ <property name="whatsThis" >
+ <string>Select your profession</string>
+ </property>
+ <property name="currentRow" >
+ <number>1</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Developer</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Student</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Fisherman</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="3" >
+ <widget class="QComboBox" name="countryCombo" >
+ <property name="toolTip" >
+ <string>Specify your country</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your country here</string>
+ </property>
+ <property name="currentIndex" >
+ <number>2</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Germany</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>India</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Norway</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>United States Of America</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>United Kingdom</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>388</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_File" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="editStyleAction" />
+ <addaction name="separator" />
+ <addaction name="exitAction" />
+ </widget>
+ <widget class="QMenu" name="menu_Help" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="aboutAction" />
+ <addaction name="separator" />
+ <addaction name="aboutQtAction" />
+ </widget>
+ <addaction name="menu_File" />
+ <addaction name="menu_Help" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <action name="exitAction" >
+ <property name="text" >
+ <string>&amp;Exit</string>
+ </property>
+ </action>
+ <action name="aboutQtAction" >
+ <property name="text" >
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="editStyleAction" >
+ <property name="text" >
+ <string>Edit &amp;Style</string>
+ </property>
+ </action>
+ <action name="aboutAction" >
+ <property name="text" >
+ <string>About</string>
+ </property>
+ </action>
+ </widget>
+ <tabstops>
+ <tabstop>maleRadioButton</tabstop>
+ <tabstop>femaleRadioButton</tabstop>
+ <tabstop>ageSpinBox</tabstop>
+ <tabstop>passwordEdit</tabstop>
+ <tabstop>professionList</tabstop>
+ <tabstop>agreeCheckBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/stylesheet/layouts/pagefold.ui b/examples/widgets/stylesheet/layouts/pagefold.ui
new file mode 100644
index 0000000000..7ae313c331
--- /dev/null
+++ b/examples/widgets/stylesheet/layouts/pagefold.ui
@@ -0,0 +1,349 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>392</width>
+ <height>412</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QFrame" name="mainFrame" >
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="0" column="1" colspan="3" >
+ <widget class="QComboBox" name="nameCombo" >
+ <property name="toolTip" >
+ <string>Specify your name</string>
+ </property>
+ <property name="editable" >
+ <bool>true</bool>
+ </property>
+ <property name="currentIndex" >
+ <number>-1</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Girish</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Jasmin</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Simon</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Zack</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QRadioButton" name="femaleRadioButton" >
+ <property name="styleSheet" >
+ <string>Check this if you are female</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Female</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="genderLabel" >
+ <property name="text" >
+ <string>Gender:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="ageLabel" >
+ <property name="text" >
+ <string>&amp;Age:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>ageSpinBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QRadioButton" name="maleRadioButton" >
+ <property name="toolTip" >
+ <string>Check this if you are male</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Male</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="nameLabel" >
+ <property name="text" >
+ <string>&amp;Name:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>nameCombo</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="passwordLabel" >
+ <property name="text" >
+ <string>&amp;Password:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>passwordEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="3" >
+ <widget class="QSpinBox" name="ageSpinBox" >
+ <property name="toolTip" >
+ <string>Specify your age</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your age</string>
+ </property>
+ <property name="minimum" >
+ <number>12</number>
+ </property>
+ <property name="value" >
+ <number>22</number>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="2" colspan="2" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" colspan="4" >
+ <widget class="QCheckBox" name="agreeCheckBox" >
+ <property name="toolTip" >
+ <string>Please read the LICENSE file before checking</string>
+ </property>
+ <property name="text" >
+ <string>I &amp;accept the terms and &amp;conditions</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="3" >
+ <widget class="QLineEdit" name="passwordEdit" >
+ <property name="toolTip" >
+ <string>Specify your password</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your password</string>
+ </property>
+ <property name="text" >
+ <string>Password</string>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" colspan="3" >
+ <widget class="QListWidget" name="professionList" >
+ <property name="toolTip" >
+ <string>Select your profession</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your name here</string>
+ </property>
+ <property name="whatsThis" >
+ <string>Specify your name here</string>
+ </property>
+ <property name="currentRow" >
+ <number>0</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Developer</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Student</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Fisherman</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Profession:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>professionList</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="3" >
+ <widget class="QComboBox" name="countryCombo" >
+ <property name="toolTip" >
+ <string>Specify country of origin</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify country of origin</string>
+ </property>
+ <property name="currentIndex" >
+ <number>6</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Egypt</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>France</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Germany</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>India</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Italy</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Korea</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Norway</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="countryLabel" >
+ <property name="text" >
+ <string>Pro&amp;fession</string>
+ </property>
+ <property name="buddy" >
+ <cstring>professionList</cstring>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>392</width>
+ <height>25</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_File" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="editStyleAction" />
+ <addaction name="separator" />
+ <addaction name="exitAction" />
+ </widget>
+ <widget class="QMenu" name="menu_Help" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="aboutAction" />
+ <addaction name="separator" />
+ <addaction name="aboutQtAction" />
+ </widget>
+ <addaction name="menu_File" />
+ <addaction name="menu_Help" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <action name="exitAction" >
+ <property name="text" >
+ <string>&amp;Exit</string>
+ </property>
+ </action>
+ <action name="aboutQtAction" >
+ <property name="text" >
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="editStyleAction" >
+ <property name="text" >
+ <string>Edit &amp;Style</string>
+ </property>
+ </action>
+ <action name="aboutAction" >
+ <property name="text" >
+ <string>About</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/stylesheet/main.cpp b/examples/widgets/stylesheet/main.cpp
new file mode 100644
index 0000000000..fd417a0c18
--- /dev/null
+++ b/examples/widgets/stylesheet/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(stylesheet);
+
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/stylesheet/mainwindow.cpp b/examples/widgets/stylesheet/mainwindow.cpp
new file mode 100644
index 0000000000..b7491e2642
--- /dev/null
+++ b/examples/widgets/stylesheet/mainwindow.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "stylesheeteditor.h"
+
+MainWindow::MainWindow()
+{
+ ui.setupUi(this);
+
+ ui.nameLabel->setProperty("class", "mandatory QLabel");
+
+ styleSheetEditor = new StyleSheetEditor(this);
+
+ statusBar()->addWidget(new QLabel(tr("Ready")));
+
+ connect(ui.exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+ connect(ui.aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::on_editStyleAction_triggered()
+{
+ styleSheetEditor->show();
+ styleSheetEditor->activateWindow();
+}
+
+void MainWindow::on_aboutAction_triggered()
+{
+ QMessageBox::about(this, tr("About Style sheet"),
+ tr("The <b>Style Sheet</b> example shows how widgets can be styled "
+ "using <a href=\"http://qt.nokia.com/doc/4.5/stylesheet.html\">Qt "
+ "Style Sheets</a>. Click <b>File|Edit Style Sheet</b> to pop up the "
+ "style editor, and either choose an existing style sheet or design "
+ "your own."));
+}
diff --git a/examples/widgets/stylesheet/mainwindow.h b/examples/widgets/stylesheet/mainwindow.h
new file mode 100644
index 0000000000..ca590ace4a
--- /dev/null
+++ b/examples/widgets/stylesheet/mainwindow.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui>
+
+#include "ui_mainwindow.h"
+
+class StyleSheetEditor;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+private slots:
+ void on_editStyleAction_triggered();
+ void on_aboutAction_triggered();
+
+private:
+ StyleSheetEditor *styleSheetEditor;
+ Ui::MainWindow ui;
+};
+
+#endif
diff --git a/examples/widgets/stylesheet/mainwindow.ui b/examples/widgets/stylesheet/mainwindow.ui
new file mode 100644
index 0000000000..cc29257afb
--- /dev/null
+++ b/examples/widgets/stylesheet/mainwindow.ui
@@ -0,0 +1,356 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>413</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Style Sheet</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QFrame" name="mainFrame" >
+ <property name="frameShape" >
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="6" column="0" colspan="5" >
+ <widget class="QCheckBox" name="agreeCheckBox" >
+ <property name="toolTip" >
+ <string>Please read the LICENSE file before checking</string>
+ </property>
+ <property name="text" >
+ <string>I accept the terms and &amp;conditions</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Profession:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
+ </property>
+ <property name="buddy" >
+ <cstring>professionList</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="nameLabel" >
+ <property name="text" >
+ <string>&amp;Name:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="buddy" >
+ <cstring>nameCombo</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QRadioButton" name="maleRadioButton" >
+ <property name="toolTip" >
+ <string>Check this if you are male</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Male</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="passwordLabel" >
+ <property name="text" >
+ <string>&amp;Password:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="buddy" >
+ <cstring>passwordEdit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="4" >
+ <widget class="QComboBox" name="countryCombo" >
+ <property name="toolTip" >
+ <string>Specify country of origin</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify country of origin</string>
+ </property>
+ <property name="currentIndex" >
+ <number>6</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Egypt</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>France</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Germany</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>India</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Italy</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Norway</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Pakistan</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="ageLabel" >
+ <property name="text" >
+ <string>&amp;Age:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="buddy" >
+ <cstring>ageSpinBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="countryLabel" >
+ <property name="text" >
+ <string>Country:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="buddy" >
+ <cstring>countryCombo</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="genderLabel" >
+ <property name="text" >
+ <string>Gender:</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="4" >
+ <widget class="QLineEdit" name="passwordEdit" >
+ <property name="toolTip" >
+ <string>Specify your password</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your password</string>
+ </property>
+ <property name="text" >
+ <string>Password</string>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" colspan="2" >
+ <widget class="QRadioButton" name="femaleRadioButton" >
+ <property name="toolTip">
+ <string>Check this if you are female</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Female</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="2" >
+ <widget class="QSpinBox" name="ageSpinBox" >
+ <property name="toolTip" >
+ <string>Specify your age</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your age</string>
+ </property>
+ <property name="minimum" >
+ <number>12</number>
+ </property>
+ <property name="value" >
+ <number>22</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="4" >
+ <widget class="QComboBox" name="nameCombo" >
+ <property name="toolTip" >
+ <string>Specify your name</string>
+ </property>
+ <property name="editable" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="4" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="3" colspan="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>61</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="7" column="3" colspan="2" >
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" colspan="4" >
+ <widget class="QListWidget" name="professionList" >
+ <property name="toolTip" >
+ <string>Select your profession</string>
+ </property>
+ <property name="statusTip" >
+ <string>Specify your name here</string>
+ </property>
+ <property name="whatsThis" >
+ <string>Specify your name here</string>
+ </property>
+ <property name="currentRow" >
+ <number>0</number>
+ </property>
+ <item>
+ <property name="text" >
+ <string>Developer</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Student</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Fisherman</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_File" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="editStyleAction" />
+ <addaction name="separator" />
+ <addaction name="exitAction" />
+ </widget>
+ <widget class="QMenu" name="menu_Help" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="aboutAction" />
+ <addaction name="aboutQtAction" />
+ </widget>
+ <addaction name="menu_File" />
+ <addaction name="menu_Help" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" />
+ <action name="exitAction" >
+ <property name="text" >
+ <string>&amp;Exit</string>
+ </property>
+ </action>
+ <action name="aboutQtAction" >
+ <property name="text" >
+ <string>About Qt</string>
+ </property>
+ </action>
+ <action name="editStyleAction" >
+ <property name="text" >
+ <string>Edit &amp;Style...</string>
+ </property>
+ </action>
+ <action name="aboutAction" >
+ <property name="text" >
+ <string>About</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/stylesheet/qss/coffee.qss b/examples/widgets/stylesheet/qss/coffee.qss
new file mode 100644
index 0000000000..4571d42d7e
--- /dev/null
+++ b/examples/widgets/stylesheet/qss/coffee.qss
@@ -0,0 +1,112 @@
+.QWidget {
+ background-color: beige;
+}
+
+/* Nice Windows-XP-style password character. */
+QLineEdit[echoMode="2"] {
+ lineedit-password-character: 9679;
+}
+
+/* We provide a min-width and min-height for push buttons
+ so that they look elegant regardless of the width of the text. */
+QPushButton {
+ background-color: palegoldenrod;
+ border-width: 2px;
+ border-color: darkkhaki;
+ border-style: solid;
+ border-radius: 5;
+ padding: 3px;
+ min-width: 9ex;
+ min-height: 2.5ex;
+}
+
+QPushButton:hover {
+ background-color: khaki;
+}
+
+/* Increase the padding, so the text is shifted when the button is
+ pressed. */
+QPushButton:pressed {
+ padding-left: 5px;
+ padding-top: 5px;
+ background-color: #d0d67c;
+}
+
+QLabel, QAbstractButton {
+ font: bold;
+}
+
+/* Mark mandatory fields with a brownish color. */
+.mandatory {
+ color: brown;
+}
+
+/* Bold text on status bar looks awful. */
+QStatusBar QLabel {
+ font: normal;
+}
+
+QStatusBar::item {
+ border-width: 1;
+ border-color: darkkhaki;
+ border-style: solid;
+ border-radius: 2;
+}
+
+QComboBox, QLineEdit, QSpinBox, QTextEdit, QListView {
+ background-color: cornsilk;
+ selection-color: #0a214c;
+ selection-background-color: #C19A6B;
+}
+
+QListView {
+ show-decoration-selected: 1;
+}
+
+QListView::item:hover {
+ background-color: wheat;
+}
+
+/* We reserve 1 pixel space in padding. When we get the focus,
+ we kill the padding and enlarge the border. This makes the items
+ glow. */
+QLineEdit, QFrame {
+ border-width: 2px;
+ padding: 1px;
+ border-style: solid;
+ border-color: darkkhaki;
+ border-radius: 5px;
+}
+
+/* As mentioned above, eliminate the padding and increase the border. */
+QLineEdit:focus, QFrame:focus {
+ border-width: 3px;
+ padding: 0px;
+}
+
+/* A QLabel is a QFrame ... */
+QLabel {
+ border: none;
+ padding: 0;
+ background: none;
+}
+
+/* A QToolTip is a QLabel ... */
+QToolTip {
+ border: 2px solid darkkhaki;
+ padding: 5px;
+ border-radius: 3px;
+ opacity: 200;
+}
+
+/* Nice to have the background color change when hovered. */
+QRadioButton:hover, QCheckBox:hover {
+ background-color: wheat;
+}
+
+/* Force the dialog's buttons to follow the Windows guidelines. */
+QDialogButtonBox {
+ button-layout: 0;
+}
+
+
diff --git a/examples/widgets/stylesheet/qss/default.qss b/examples/widgets/stylesheet/qss/default.qss
new file mode 100644
index 0000000000..84eb5e0bc2
--- /dev/null
+++ b/examples/widgets/stylesheet/qss/default.qss
@@ -0,0 +1 @@
+/* empty stylesheet */
diff --git a/examples/widgets/stylesheet/qss/pagefold.qss b/examples/widgets/stylesheet/qss/pagefold.qss
new file mode 100644
index 0000000000..3701fc713c
--- /dev/null
+++ b/examples/widgets/stylesheet/qss/pagefold.qss
@@ -0,0 +1,299 @@
+/* Customize any plain widget that is a child of a QMainWindow. */
+QMainWindow > .QWidget {
+ background-color: gainsboro;
+ background-image: url(:/images/pagefold.png);
+ background-position: top right;
+ background-repeat: no-repeat
+}
+
+/* Provide a padding for the layout inside the frame. The frame
+ exists only to provide a padding for the top-right image, so we
+ explicitly disable the border. */
+#mainFrame {
+ padding-right: 30px;
+ border-style: none;
+ border-image: none; /* since we set a border-image below */
+}
+
+/* mainFrame won't have this border-image since we have
+ explicitly set it to 'none' using a more specific selector. */
+QFrame, QLineEdit, QComboBox[editable="true"], QSpinBox {
+ border-image: url(:/images/frame.png) 4;
+ border-width: 3;
+}
+
+QLabel {
+ border: none;
+ border-image: none;
+ padding: 0;
+ background: none;
+}
+
+/* Make text in message boxes selectable. */
+QMessageBox {
+ /* LinksAccessibleByMouse | TextSelectableByMouse */
+ messagebox-text-interaction-flags: 5;
+}
+
+/* Set the selection colors for all widgets. */
+QWidget {
+ selection-color: black;
+ selection-background-color: Silver;
+ color: black;
+}
+
+/* Make the entire row selected in item views. */
+QAbstractItemView {
+ show-decoration-selected: 1;
+}
+
+/* Nice WindowsXP-style password character for password line edits. */
+QLineEdit[echoMode="2"] {
+ lineedit-password-character: 9679;
+}
+
+/* Customize tooltips. */
+QToolTip {
+ background-color: rgb(200,200,255);
+ border-color: darkslategray;
+ border-width: 1px;
+ border-style: solid;
+ padding: 3px;
+ font: bold;
+ border-radius: 3px;
+ opacity: 200;
+}
+
+/* Customize radio buttons. */
+
+QRadioButton {
+ spacing: 5px;
+}
+
+QRadioButton::indicator {
+ width: 13px;
+ height: 13px;
+}
+
+QRadioButton::indicator::unchecked {
+ image: url(:/images/radiobutton_unchecked.png);
+}
+
+QRadioButton::indicator:unchecked:hover {
+ image: url(:/images/radiobutton_unchecked_hover.png);
+}
+
+QRadioButton::indicator:unchecked:pressed {
+ image: url(:/images/radiobutton_unchecked_pressed.png);
+}
+
+QRadioButton::indicator::checked {
+ image: url(:/images/radiobutton_checked.png);
+}
+
+QRadioButton::indicator:checked:hover {
+ image: url(:/images/radiobutton_checked_hover.png);
+}
+
+QRadioButton::indicator:checked:pressed {
+ image: url(:/images/radiobutton_checked_pressed.png);
+}
+
+/* Customize arrows. */
+
+*::down-arrow, *::menu-indicator {
+ image: url(:/images/down_arrow.png);
+ width: 7px;
+ height: 7px;
+}
+
+*::down-arrow:disabled, *::down-arrow:off {
+ image: url(:/images/down_arrow_disabled.png);
+}
+
+*::up-arrow {
+ image: url(:/images/up_arrow.png);
+ width: 7px;
+ height: 7px;
+}
+
+*::up-arrow:disabled, *::up-arrow:off {
+ image: url(:/images/up_arrow_disabled.png);
+}
+
+/* Customize push buttons and comboboxes. Our read-only combobox
+ is very similar to a push button, so they share the same border image. */
+
+QPushButton {
+ min-width: 4em;
+}
+
+QPushButton, QComboBox[editable="false"],
+QComboBox[editable="true"]::drop-down {
+ border-image: url(:/images/pushbutton.png) 5;
+ border-width: 5;
+}
+
+QPushButton:hover, QComboBox[editable="false"]:hover,
+QComboBox[editable="true"]::drop-down:hover, QMenuBar::item:hover {
+ border-image: url(:/images/pushbutton_hover.png) 5;
+ border-width: 5;
+}
+
+QPushButton:pressed, QComboBox[editable="false"]:on,
+QComboBox[editable="true"]::drop-down:on, QMenuBar::item:on {
+ border-image: url(:/images/pushbutton_pressed.png) 5;
+ border-width: 5;
+}
+
+/* Customize read-only comboboxes. */
+
+QComboBox[editable="false"] {
+ padding-left: 3px;
+ padding-right: 20px; /* space for the arrow */
+}
+
+QComboBox[editable="false"]::drop-down {
+ subcontrol-origin: padding;
+ subcontrol-position: top right;
+ width: 15px;
+ border-left-style: solid;
+ border-left-color: darkgray;
+ border-left-width: 1px;
+}
+
+QComboBox[editable="false"]::down-arrow {
+ subcontrol-origin: content;
+ subcontrol-position: center;
+ position: relative;
+ left: 1px; /* 1 pixel dropdown border */
+}
+
+/* The combobox arrow is on when the popup is open. */
+QComboBox[editable="false"]::down-arrow:on {
+ position: relative;
+ top: 1px;
+ left: 2px;
+}
+
+/* Customize editable comboboxes. */
+
+QComboBox[editable="true"] {
+ padding-right: 16px;
+}
+
+QComboBox[editable="true"]::drop-down {
+ subcontrol-origin: border;
+ subcontrol-position: top right;
+ width: 13px;
+ position: absolute;
+ top: 2px;
+ bottom: 2px;
+ right: 2px;
+}
+
+QComboBox[editable="true"]::drop-down,
+QComboBox[editable="true"]::drop-down:hover,
+QComboBox[editable="true"]::drop-down:on {
+ border-width: 0px;
+ border-left-width: 3px; /* we need only left and center part */
+}
+
+/* Shift the arrow when it's open. */
+QComboBox[editable="true"]::down-arrow:on {
+ position: relative;
+ top: 1px;
+ left: 1px;
+}
+
+/* Customize check boxes. */
+QCheckBox {
+ spacing: 5px;
+}
+
+QCheckBox::indicator {
+ width: 13px;
+ height: 13px;
+}
+
+QCheckBox::indicator:unchecked {
+ image: url(:/images/checkbox_unchecked.png);
+}
+
+QCheckBox::indicator:unchecked:hover {
+ image: url(:/images/checkbox_unchecked_hover.png);
+}
+
+QCheckBox::indicator:unchecked:pressed {
+ image: url(:/images/checkbox_unchecked_pressed.png);
+}
+
+QCheckBox::indicator:checked {
+ image: url(:/images/checkbox_checked.png);
+}
+
+QCheckBox::indicator:checked:hover {
+ image: url(:/images/checkbox_checked_hover.png);
+}
+
+QCheckBox::indicator:checked:pressed {
+ image: url(:/images/checkbox_checked_pressed.png);
+}
+
+/* Customize the size grip. */
+QSizeGrip {
+ image: url(:/images/sizegrip.png);
+ width: 16px;
+ height: 16px;
+}
+
+/* Customize the menu bar. */
+QMenuBar {
+ border-image: none;
+ border-style: none;
+ border-width: 1px;
+ border-bottom-style: solid;
+ border-bottom-color: darkslategray;
+ padding: 2px;
+}
+
+/* Customize spin boxes. */
+
+QSpinBox {
+ padding-right: 15px;
+}
+
+QSpinBox::up-button {
+ subcontrol-origin: border;
+ subcontrol-position: top right;
+
+ width: 16px; /* 16 + 2*1px border-width = 15px padding + 3px parent border */
+ border-image: url(:/images/spinup.png) 1;
+ border-width: 1px;
+}
+
+QSpinBox::up-button:hover {
+ border-image: url(:/images/spinup_hover.png) 1;
+}
+
+QSpinBox::up-button:pressed {
+ border-image: url(:/images/spinup_pressed.png) 1;
+}
+
+QSpinBox::down-button {
+ subcontrol-origin: border;
+ subcontrol-position: bottom right;
+
+ width: 16px;
+ border-image: url(:/images/spindown.png) 1;
+ border-width: 1px;
+ border-top-width: 0;
+}
+
+QSpinBox::down-button:hover {
+ border-image: url(:/images/spindown_hover.png) 1;
+}
+
+QSpinBox::down-button:pressed {
+ border-image: url(:/images/spindown_pressed.png) 1;
+}
diff --git a/examples/widgets/stylesheet/stylesheet.pro b/examples/widgets/stylesheet/stylesheet.pro
new file mode 100644
index 0000000000..d677d4eefc
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheet.pro
@@ -0,0 +1,16 @@
+HEADERS = mainwindow.h \
+ stylesheeteditor.h
+FORMS = mainwindow.ui \
+ stylesheeteditor.ui
+RESOURCES = stylesheet.qrc
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ stylesheeteditor.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/stylesheet
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro images layouts qss
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/stylesheet
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/stylesheet/stylesheet.qrc b/examples/widgets/stylesheet/stylesheet.qrc
new file mode 100644
index 0000000000..e1e61a920a
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheet.qrc
@@ -0,0 +1,39 @@
+<RCC>
+<qresource prefix="/">
+ <file>layouts/default.ui</file>
+ <file>layouts/pagefold.ui</file>
+ <file>qss/coffee.qss</file>
+ <file>qss/default.qss</file>
+ <file>qss/pagefold.qss</file>
+ <file>images/pagefold.png</file>
+ <file>images/frame.png</file>
+ <file>images/radiobutton_unchecked.png</file>
+ <file>images/radiobutton_unchecked_pressed.png</file>
+ <file>images/radiobutton_unchecked_hover.png</file>
+ <file>images/radiobutton_checked.png</file>
+ <file>images/radiobutton_checked_pressed.png</file>
+ <file>images/radiobutton_checked_hover.png</file>
+ <file>images/pushbutton.png</file>
+ <file>images/pushbutton_hover.png</file>
+ <file>images/pushbutton_pressed.png</file>
+ <file>images/checkbox_unchecked.png</file>
+ <file>images/checkbox_unchecked_pressed.png</file>
+ <file>images/checkbox_unchecked_hover.png</file>
+ <file>images/checkbox_checked.png</file>
+ <file>images/checkbox_checked_pressed.png</file>
+ <file>images/checkbox_checked_hover.png</file>
+ <file>images/down_arrow.png</file>
+ <file>images/down_arrow_disabled.png</file>
+ <file>images/up_arrow.png</file>
+ <file>images/up_arrow_disabled.png</file>
+ <file>images/sizegrip.png</file>
+ <file>images/spinup.png</file>
+ <file>images/spinup_off.png</file>
+ <file>images/spinup_hover.png</file>
+ <file>images/spinup_pressed.png</file>
+ <file>images/spindown.png</file>
+ <file>images/spindown_off.png</file>
+ <file>images/spindown_hover.png</file>
+ <file>images/spindown_pressed.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/stylesheet/stylesheeteditor.cpp
new file mode 100644
index 0000000000..c1d43ea99b
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheeteditor.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "stylesheeteditor.h"
+
+StyleSheetEditor::StyleSheetEditor(QWidget *parent)
+ : QDialog(parent)
+{
+ ui.setupUi(this);
+
+ QRegExp regExp(".(.*)\\+?Style");
+ QString defaultStyle = QApplication::style()->metaObject()->className();
+
+ if (regExp.exactMatch(defaultStyle))
+ defaultStyle = regExp.cap(1);
+
+ ui.styleCombo->addItems(QStyleFactory::keys());
+ ui.styleCombo->setCurrentIndex(ui.styleCombo->findText(defaultStyle, Qt::MatchContains));
+ ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Coffee"));
+ loadStyleSheet("Coffee");
+}
+
+void StyleSheetEditor::on_styleCombo_activated(const QString &styleName)
+{
+ qApp->setStyle(styleName);
+ ui.applyButton->setEnabled(false);
+}
+
+void StyleSheetEditor::on_styleSheetCombo_activated(const QString &sheetName)
+{
+ loadStyleSheet(sheetName);
+}
+
+void StyleSheetEditor::on_styleTextEdit_textChanged()
+{
+ ui.applyButton->setEnabled(true);
+}
+
+void StyleSheetEditor::on_applyButton_clicked()
+{
+ qApp->setStyleSheet(ui.styleTextEdit->toPlainText());
+ ui.applyButton->setEnabled(false);
+}
+
+void StyleSheetEditor::loadStyleSheet(const QString &sheetName)
+{
+ QFile file(":/qss/" + sheetName.toLower() + ".qss");
+ file.open(QFile::ReadOnly);
+ QString styleSheet = QLatin1String(file.readAll());
+
+ ui.styleTextEdit->setPlainText(styleSheet);
+ qApp->setStyleSheet(styleSheet);
+ ui.applyButton->setEnabled(false);
+}
diff --git a/examples/widgets/stylesheet/stylesheeteditor.h b/examples/widgets/stylesheet/stylesheeteditor.h
new file mode 100644
index 0000000000..b2dfd431ed
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheeteditor.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STYLESHEETEDITOR_H
+#define STYLESHEETEDITOR_H
+
+#include <QDialog>
+
+#include "ui_stylesheeteditor.h"
+
+class StyleSheetEditor : public QDialog
+{
+ Q_OBJECT
+
+public:
+ StyleSheetEditor(QWidget *parent = 0);
+
+private slots:
+ void on_styleCombo_activated(const QString &styleName);
+ void on_styleSheetCombo_activated(const QString &styleSheetName);
+ void on_styleTextEdit_textChanged();
+ void on_applyButton_clicked();
+
+private:
+ void loadStyleSheet(const QString &sheetName);
+
+ Ui::StyleSheetEditor ui;
+};
+
+#endif
diff --git a/examples/widgets/stylesheet/stylesheeteditor.ui b/examples/widgets/stylesheet/stylesheeteditor.ui
new file mode 100644
index 0000000000..34cd7f6d04
--- /dev/null
+++ b/examples/widgets/stylesheet/stylesheeteditor.ui
@@ -0,0 +1,171 @@
+<ui version="4.0" >
+ <class>StyleSheetEditor</class>
+ <widget class="QWidget" name="StyleSheetEditor" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>445</width>
+ <height>289</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Style Editor</string>
+ </property>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item row="0" column="6" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::MinimumExpanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>32</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::MinimumExpanding</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>32</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="5" >
+ <widget class="QComboBox" name="styleSheetCombo" >
+ <item>
+ <property name="text" >
+ <string>Default</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Coffee</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>Pagefold</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>10</width>
+ <height>16</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QComboBox" name="styleCombo" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>5</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLabel" name="label_7" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Style:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="7" >
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>321</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="applyButton" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>&amp;Apply</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" colspan="7" >
+ <widget class="QTextEdit" name="styleTextEdit" />
+ </item>
+ <item row="0" column="4" >
+ <widget class="QLabel" name="label_8" >
+ <property name="sizePolicy" >
+ <sizepolicy>
+ <hsizetype>0</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>Style Sheet:</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/widgets/tablet/main.cpp b/examples/widgets/tablet/main.cpp
new file mode 100644
index 0000000000..27aab50901
--- /dev/null
+++ b/examples/widgets/tablet/main.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "tabletapplication.h"
+#include "tabletcanvas.h"
+
+//! [0]
+int main(int argv, char *args[])
+{
+ TabletApplication app(argv, args);
+ TabletCanvas *canvas = new TabletCanvas;
+ app.setCanvas(canvas);
+
+ MainWindow mainWindow(canvas);
+ mainWindow.resize(500, 500);
+ mainWindow.show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/tablet/mainwindow.cpp b/examples/widgets/tablet/mainwindow.cpp
new file mode 100644
index 0000000000..8ae3431354
--- /dev/null
+++ b/examples/widgets/tablet/mainwindow.cpp
@@ -0,0 +1,274 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "tabletcanvas.h"
+
+//! [0]
+MainWindow::MainWindow(TabletCanvas *canvas)
+{
+ myCanvas = canvas;
+ createActions();
+ createMenus();
+
+ myCanvas->setColor(Qt::red);
+ myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
+ myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
+ myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
+
+ setWindowTitle(tr("Tablet Example"));
+ setCentralWidget(myCanvas);
+}
+//! [0]
+
+//! [1]
+void MainWindow::brushColorAct()
+{
+ QColor color = QColorDialog::getColor(myCanvas->color());
+
+ if (color.isValid())
+ myCanvas->setColor(color);
+}
+//! [1]
+
+//! [2]
+void MainWindow::alphaActionTriggered(QAction *action)
+{
+ if (action == alphaChannelPressureAction) {
+ myCanvas->setAlphaChannelType(TabletCanvas::AlphaPressure);
+ } else if (action == alphaChannelTiltAction) {
+ myCanvas->setAlphaChannelType(TabletCanvas::AlphaTilt);
+ } else {
+ myCanvas->setAlphaChannelType(TabletCanvas::NoAlpha);
+ }
+}
+//! [2]
+
+//! [3]
+void MainWindow::lineWidthActionTriggered(QAction *action)
+{
+ if (action == lineWidthPressureAction) {
+ myCanvas->setLineWidthType(TabletCanvas::LineWidthPressure);
+ } else if (action == lineWidthTiltAction) {
+ myCanvas->setLineWidthType(TabletCanvas::LineWidthTilt);
+ } else {
+ myCanvas->setLineWidthType(TabletCanvas::NoLineWidth);
+ }
+}
+//! [3]
+
+//! [4]
+void MainWindow::saturationActionTriggered(QAction *action)
+{
+ if (action == colorSaturationVTiltAction) {
+ myCanvas->setColorSaturationType(TabletCanvas::SaturationVTilt);
+ } else if (action == colorSaturationHTiltAction) {
+ myCanvas->setColorSaturationType(TabletCanvas::SaturationHTilt);
+ } else if (action == colorSaturationPressureAction) {
+ myCanvas->setColorSaturationType(TabletCanvas::SaturationPressure);
+ } else {
+ myCanvas->setColorSaturationType(TabletCanvas::NoSaturation);
+ }
+}
+//! [4]
+
+//! [5]
+void MainWindow::saveAct()
+{
+ QString path = QDir::currentPath() + "/untitled.png";
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save Picture"),
+ path);
+
+ if (!myCanvas->saveImage(fileName))
+ QMessageBox::information(this, "Error Saving Picture",
+ "Could not save the image");
+}
+//! [5]
+
+//! [6]
+void MainWindow::loadAct()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open Picture"),
+ QDir::currentPath());
+
+ if (!myCanvas->loadImage(fileName))
+ QMessageBox::information(this, "Error Opening Picture",
+ "Could not open picture");
+}
+//! [6]
+
+//! [7]
+void MainWindow::aboutAct()
+{
+ QMessageBox::about(this, tr("About Tablet Example"),
+ tr("This example shows use of a Wacom tablet in Qt"));
+}
+//! [7]
+
+//! [8]
+void MainWindow::createActions()
+{
+//! [8]
+ brushColorAction = new QAction(tr("&Brush Color..."), this);
+ brushColorAction->setShortcut(tr("Ctrl+C"));
+ connect(brushColorAction, SIGNAL(triggered()),
+ this, SLOT(brushColorAct()));
+
+//! [9]
+ alphaChannelPressureAction = new QAction(tr("&Pressure"), this);
+ alphaChannelPressureAction->setCheckable(true);
+
+ alphaChannelTiltAction = new QAction(tr("&Tilt"), this);
+ alphaChannelTiltAction->setCheckable(true);
+
+ noAlphaChannelAction = new QAction(tr("No Alpha Channel"), this);
+ noAlphaChannelAction->setCheckable(true);
+ noAlphaChannelAction->setChecked(true);
+
+ alphaChannelGroup = new QActionGroup(this);
+ alphaChannelGroup->addAction(alphaChannelPressureAction);
+ alphaChannelGroup->addAction(alphaChannelTiltAction);
+ alphaChannelGroup->addAction(noAlphaChannelAction);
+ connect(alphaChannelGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(alphaActionTriggered(QAction*)));
+
+//! [9]
+ colorSaturationVTiltAction = new QAction(tr("&Vertical Tilt"), this);
+ colorSaturationVTiltAction->setCheckable(true);
+
+ colorSaturationHTiltAction = new QAction(tr("&Horizontal Tilt"), this);
+ colorSaturationHTiltAction->setCheckable(true);
+
+ colorSaturationPressureAction = new QAction(tr("&Pressure"), this);
+ colorSaturationPressureAction->setCheckable(true);
+
+ noColorSaturationAction = new QAction(tr("&No Color Saturation"), this);
+ noColorSaturationAction->setCheckable(true);
+ noColorSaturationAction->setChecked(true);
+
+ colorSaturationGroup = new QActionGroup(this);
+ colorSaturationGroup->addAction(colorSaturationVTiltAction);
+ colorSaturationGroup->addAction(colorSaturationHTiltAction);
+ colorSaturationGroup->addAction(colorSaturationPressureAction);
+ colorSaturationGroup->addAction(noColorSaturationAction);
+ connect(colorSaturationGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(saturationActionTriggered(QAction*)));
+
+ lineWidthPressureAction = new QAction(tr("&Pressure"), this);
+ lineWidthPressureAction->setCheckable(true);
+ lineWidthPressureAction->setChecked(true);
+
+ lineWidthTiltAction = new QAction(tr("&Tilt"), this);
+ lineWidthTiltAction->setCheckable(true);
+
+ lineWidthFixedAction = new QAction(tr("&Fixed"), this);
+ lineWidthFixedAction->setCheckable(true);
+
+ lineWidthGroup = new QActionGroup(this);
+ lineWidthGroup->addAction(lineWidthPressureAction);
+ lineWidthGroup->addAction(lineWidthTiltAction);
+ lineWidthGroup->addAction(lineWidthFixedAction);
+ connect(lineWidthGroup, SIGNAL(triggered(QAction*)),
+ this, SLOT(lineWidthActionTriggered(QAction*)));
+
+ exitAction = new QAction(tr("E&xit"), this);
+ exitAction->setShortcuts(QKeySequence::Quit);
+ connect(exitAction, SIGNAL(triggered()),
+ this, SLOT(close()));
+
+ loadAction = new QAction(tr("&Open..."), this);
+ loadAction->setShortcuts(QKeySequence::Open);
+ connect(loadAction, SIGNAL(triggered()),
+ this, SLOT(loadAct()));
+
+ saveAction = new QAction(tr("&Save As..."), this);
+ saveAction->setShortcuts(QKeySequence::SaveAs);
+ connect(saveAction, SIGNAL(triggered()),
+ this, SLOT(saveAct()));
+
+ aboutAction = new QAction(tr("A&bout"), this);
+ aboutAction->setShortcut(tr("Ctrl+B"));
+ connect(aboutAction, SIGNAL(triggered()),
+ this, SLOT(aboutAct()));
+
+ aboutQtAction = new QAction(tr("About &Qt"), this);
+ aboutQtAction->setShortcut(tr("Ctrl+Q"));
+ connect(aboutQtAction, SIGNAL(triggered()),
+ qApp, SLOT(aboutQt()));
+//! [10]
+}
+//! [10]
+
+//! [11]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(loadAction);
+ fileMenu->addAction(saveAction);
+ fileMenu->addSeparator();
+ fileMenu->addAction(exitAction);
+
+ brushMenu = menuBar()->addMenu(tr("&Brush"));
+ brushMenu->addAction(brushColorAction);
+
+ tabletMenu = menuBar()->addMenu(tr("&Tablet"));
+
+ lineWidthMenu = tabletMenu->addMenu(tr("&Line Width"));
+ lineWidthMenu->addAction(lineWidthPressureAction);
+ lineWidthMenu->addAction(lineWidthTiltAction);
+ lineWidthMenu->addAction(lineWidthFixedAction);
+
+ alphaChannelMenu = tabletMenu->addMenu(tr("&Alpha Channel"));
+ alphaChannelMenu->addAction(alphaChannelPressureAction);
+ alphaChannelMenu->addAction(alphaChannelTiltAction);
+ alphaChannelMenu->addAction(noAlphaChannelAction);
+
+ colorSaturationMenu = tabletMenu->addMenu(tr("&Color Saturation"));
+ colorSaturationMenu->addAction(colorSaturationVTiltAction);
+ colorSaturationMenu->addAction(colorSaturationHTiltAction);
+ colorSaturationMenu->addAction(noColorSaturationAction);
+
+ helpMenu = menuBar()->addMenu("&Help");
+ helpMenu->addAction(aboutAction);
+ helpMenu->addAction(aboutQtAction);
+}
+//! [11]
diff --git a/examples/widgets/tablet/mainwindow.h b/examples/widgets/tablet/mainwindow.h
new file mode 100644
index 0000000000..6d3a11af61
--- /dev/null
+++ b/examples/widgets/tablet/mainwindow.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QActionGroup;
+class QMenu;
+class QStatusBar;
+QT_END_NAMESPACE
+class TabletCanvas;
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(TabletCanvas *canvas);
+
+private slots:
+ void brushColorAct();
+ void alphaActionTriggered(QAction *action);
+ void lineWidthActionTriggered(QAction *action);
+ void saturationActionTriggered(QAction *action);
+ void saveAct();
+ void loadAct();
+ void aboutAct();
+
+private:
+ void createActions();
+ void createMenus();
+
+ TabletCanvas *myCanvas;
+
+ QAction *brushColorAction;
+ QActionGroup *brushActionGroup;
+
+ QActionGroup *alphaChannelGroup;
+ QAction *alphaChannelPressureAction;
+ QAction *alphaChannelTiltAction;
+ QAction *noAlphaChannelAction;
+
+ QActionGroup *colorSaturationGroup;
+ QAction *colorSaturationVTiltAction;
+ QAction *colorSaturationHTiltAction;
+ QAction *colorSaturationPressureAction;
+ QAction *noColorSaturationAction;
+
+ QActionGroup *lineWidthGroup;
+ QAction *lineWidthPressureAction;
+ QAction *lineWidthTiltAction;
+ QAction *lineWidthFixedAction;
+
+ QAction *exitAction;
+ QAction *saveAction;
+ QAction *loadAction;
+
+ QAction *aboutAction;
+ QAction *aboutQtAction;
+
+ QMenu *fileMenu;
+ QMenu *brushMenu;
+ QMenu *tabletMenu;
+ QMenu *helpMenu;
+ QMenu *colorSaturationMenu;
+ QMenu *lineWidthMenu;
+ QMenu *alphaChannelMenu;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tablet/tablet.pro b/examples/widgets/tablet/tablet.pro
new file mode 100644
index 0000000000..4229ed0aaa
--- /dev/null
+++ b/examples/widgets/tablet/tablet.pro
@@ -0,0 +1,15 @@
+HEADERS = mainwindow.h \
+ tabletcanvas.h \
+ tabletapplication.h
+SOURCES = mainwindow.cpp \
+ main.cpp \
+ tabletcanvas.cpp \
+ tabletapplication.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tablet
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tablet.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tablet
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/tablet/tabletapplication.cpp b/examples/widgets/tablet/tabletapplication.cpp
new file mode 100644
index 0000000000..7f60136b12
--- /dev/null
+++ b/examples/widgets/tablet/tabletapplication.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "tabletapplication.h"
+
+//! [0]
+bool TabletApplication::event(QEvent *event)
+{
+ if (event->type() == QEvent::TabletEnterProximity ||
+ event->type() == QEvent::TabletLeaveProximity) {
+ myCanvas->setTabletDevice(
+ static_cast<QTabletEvent *>(event)->device());
+ return true;
+ }
+ return QApplication::event(event);
+}
+//! [0]
diff --git a/examples/widgets/tablet/tabletapplication.h b/examples/widgets/tablet/tabletapplication.h
new file mode 100644
index 0000000000..064c5af964
--- /dev/null
+++ b/examples/widgets/tablet/tabletapplication.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABLETAPPLICATION_H
+#define TABLETAPPLICATION_H
+
+#include <QApplication>
+
+#include "tabletcanvas.h"
+
+//! [0]
+class TabletApplication : public QApplication
+{
+ Q_OBJECT
+
+public:
+ TabletApplication(int &argv, char **args)
+ : QApplication(argv, args) {}
+
+ bool event(QEvent *event);
+ void setCanvas(TabletCanvas *canvas)
+ { myCanvas = canvas; }
+
+private:
+ TabletCanvas *myCanvas;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tablet/tabletcanvas.cpp b/examples/widgets/tablet/tabletcanvas.cpp
new file mode 100644
index 0000000000..88a582de23
--- /dev/null
+++ b/examples/widgets/tablet/tabletcanvas.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <math.h>
+
+#include "tabletcanvas.h"
+
+//! [0]
+TabletCanvas::TabletCanvas()
+{
+ resize(500, 500);
+ myBrush = QBrush();
+ myPen = QPen();
+ initPixmap();
+ setAutoFillBackground(true);
+ deviceDown = false;
+ myColor = Qt::red;
+ myTabletDevice = QTabletEvent::Stylus;
+ alphaChannelType = NoAlpha;
+ colorSaturationType = NoSaturation;
+ lineWidthType = LineWidthPressure;
+}
+
+void TabletCanvas::initPixmap()
+{
+ QPixmap newPixmap = QPixmap(width(), height());
+ newPixmap.fill(Qt::white);
+ QPainter painter(&newPixmap);
+ if (!pixmap.isNull())
+ painter.drawPixmap(0, 0, pixmap);
+ painter.end();
+ pixmap = newPixmap;
+}
+//! [0]
+
+//! [1]
+bool TabletCanvas::saveImage(const QString &file)
+{
+ return pixmap.save(file);
+}
+//! [1]
+
+//! [2]
+bool TabletCanvas::loadImage(const QString &file)
+{
+ bool success = pixmap.load(file);
+
+ if (success) {
+ update();
+ return true;
+ }
+ return false;
+}
+//! [2]
+
+//! [3]
+void TabletCanvas::tabletEvent(QTabletEvent *event)
+{
+
+ switch (event->type()) {
+ case QEvent::TabletPress:
+ if (!deviceDown) {
+ deviceDown = true;
+ polyLine[0] = polyLine[1] = polyLine[2] = event->pos();
+ }
+ break;
+ case QEvent::TabletRelease:
+ if (deviceDown)
+ deviceDown = false;
+ break;
+ case QEvent::TabletMove:
+ polyLine[2] = polyLine[1];
+ polyLine[1] = polyLine[0];
+ polyLine[0] = event->pos();
+
+ if (deviceDown) {
+ updateBrush(event);
+ QPainter painter(&pixmap);
+ paintPixmap(painter, event);
+ }
+ break;
+ default:
+ break;
+ }
+ update();
+}
+//! [3]
+
+//! [4]
+void TabletCanvas::paintEvent(QPaintEvent *)
+{
+ QPainter painter(this);
+ painter.drawPixmap(0, 0, pixmap);
+}
+//! [4]
+
+//! [5]
+void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
+{
+ QPoint brushAdjust(10, 10);
+
+ switch (myTabletDevice) {
+ case QTabletEvent::Airbrush:
+ myBrush.setColor(myColor);
+ myBrush.setStyle(brushPattern(event->pressure()));
+ painter.setPen(Qt::NoPen);
+ painter.setBrush(myBrush);
+
+ for (int i = 0; i < 3; ++i) {
+ painter.drawEllipse(QRect(polyLine[i] - brushAdjust,
+ polyLine[i] + brushAdjust));
+ }
+ break;
+ case QTabletEvent::Puck:
+ case QTabletEvent::FourDMouse:
+ case QTabletEvent::RotationStylus:
+ {
+ const QString error(tr("This input device is not supported by the example."));
+#ifndef QT_NO_STATUSTIP
+ QStatusTipEvent status(error);
+ QApplication::sendEvent(this, &status);
+#else
+ qWarning() << error;
+#endif
+ }
+ break;
+ default:
+ {
+ const QString error(tr("Unknown tablet device - treating as stylus"));
+#ifndef QT_NO_STATUSTIP
+ QStatusTipEvent status(error);
+ QApplication::sendEvent(this, &status);
+#else
+ qWarning() << error;
+#endif
+ }
+ // FALL-THROUGH
+ case QTabletEvent::Stylus:
+ painter.setBrush(myBrush);
+ painter.setPen(myPen);
+ painter.drawLine(polyLine[1], event->pos());
+ break;
+ }
+}
+//! [5]
+
+//! [6]
+Qt::BrushStyle TabletCanvas::brushPattern(qreal value)
+{
+ int pattern = int((value) * 100.0) % 7;
+
+ switch (pattern) {
+ case 0:
+ return Qt::SolidPattern;
+ case 1:
+ return Qt::Dense1Pattern;
+ case 2:
+ return Qt::Dense2Pattern;
+ case 3:
+ return Qt::Dense3Pattern;
+ case 4:
+ return Qt::Dense4Pattern;
+ case 5:
+ return Qt::Dense5Pattern;
+ case 6:
+ return Qt::Dense6Pattern;
+ default:
+ return Qt::Dense7Pattern;
+ }
+}
+//! [6]
+
+//! [7]
+void TabletCanvas::updateBrush(QTabletEvent *event)
+{
+ int hue, saturation, value, alpha;
+ myColor.getHsv(&hue, &saturation, &value, &alpha);
+
+ int vValue = int(((event->yTilt() + 60.0) / 120.0) * 255);
+ int hValue = int(((event->xTilt() + 60.0) / 120.0) * 255);
+//! [7] //! [8]
+
+ switch (alphaChannelType) {
+ case AlphaPressure:
+ myColor.setAlpha(int(event->pressure() * 255.0));
+ break;
+ case AlphaTilt:
+ myColor.setAlpha(maximum(abs(vValue - 127), abs(hValue - 127)));
+ break;
+ default:
+ myColor.setAlpha(255);
+ }
+
+//! [8] //! [9]
+ switch (colorSaturationType) {
+ case SaturationVTilt:
+ myColor.setHsv(hue, vValue, value, alpha);
+ break;
+ case SaturationHTilt:
+ myColor.setHsv(hue, hValue, value, alpha);
+ break;
+ case SaturationPressure:
+ myColor.setHsv(hue, int(event->pressure() * 255.0), value, alpha);
+ break;
+ default:
+ ;
+ }
+
+//! [9] //! [10]
+ switch (lineWidthType) {
+ case LineWidthPressure:
+ myPen.setWidthF(event->pressure() * 10 + 1);
+ break;
+ case LineWidthTilt:
+ myPen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12);
+ break;
+ default:
+ myPen.setWidthF(1);
+ }
+
+//! [10] //! [11]
+ if (event->pointerType() == QTabletEvent::Eraser) {
+ myBrush.setColor(Qt::white);
+ myPen.setColor(Qt::white);
+ myPen.setWidthF(event->pressure() * 10 + 1);
+ } else {
+ myBrush.setColor(myColor);
+ myPen.setColor(myColor);
+ }
+}
+//! [11]
+
+void TabletCanvas::resizeEvent(QResizeEvent *)
+{
+ initPixmap();
+ polyLine[0] = polyLine[1] = polyLine[2] = QPoint();
+}
diff --git a/examples/widgets/tablet/tabletcanvas.h b/examples/widgets/tablet/tabletcanvas.h
new file mode 100644
index 0000000000..591a5f3f7d
--- /dev/null
+++ b/examples/widgets/tablet/tabletcanvas.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TABLETCANVAS_H
+#define TABLETCANVAS_H
+
+#include <QWidget>
+#include <QPixmap>
+#include <QPoint>
+#include <QTabletEvent>
+#include <QColor>
+#include <QBrush>
+#include <QPen>
+#include <QPoint>
+
+QT_BEGIN_NAMESPACE
+class QPaintEvent;
+class QString;
+QT_END_NAMESPACE
+
+//! [0]
+class TabletCanvas : public QWidget
+{
+ Q_OBJECT
+
+public:
+ enum AlphaChannelType { AlphaPressure, AlphaTilt, NoAlpha };
+ enum ColorSaturationType { SaturationVTilt, SaturationHTilt,
+ SaturationPressure, NoSaturation };
+ enum LineWidthType { LineWidthPressure, LineWidthTilt, NoLineWidth };
+
+ TabletCanvas();
+
+ bool saveImage(const QString &file);
+ bool loadImage(const QString &file);
+ void setAlphaChannelType(AlphaChannelType type)
+ { alphaChannelType = type; }
+ void setColorSaturationType(ColorSaturationType type)
+ { colorSaturationType = type; }
+ void setLineWidthType(LineWidthType type)
+ { lineWidthType = type; }
+ void setColor(const QColor &color)
+ { myColor = color; }
+ QColor color() const
+ { return myColor; }
+ void setTabletDevice(QTabletEvent::TabletDevice device)
+ { myTabletDevice = device; }
+ int maximum(int a, int b)
+ { return a > b ? a : b; }
+
+protected:
+ void tabletEvent(QTabletEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+private:
+ void initPixmap();
+ void paintPixmap(QPainter &painter, QTabletEvent *event);
+ Qt::BrushStyle brushPattern(qreal value);
+ void updateBrush(QTabletEvent *event);
+
+ AlphaChannelType alphaChannelType;
+ ColorSaturationType colorSaturationType;
+ LineWidthType lineWidthType;
+ QTabletEvent::PointerType pointerType;
+ QTabletEvent::TabletDevice myTabletDevice;
+ QColor myColor;
+
+ QPixmap pixmap;
+ QBrush myBrush;
+ QPen myPen;
+ bool deviceDown;
+ QPoint polyLine[3];
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tetrix/main.cpp b/examples/widgets/tetrix/main.cpp
new file mode 100644
index 0000000000..9a7dcf35e5
--- /dev/null
+++ b/examples/widgets/tetrix/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <stdlib.h>
+
+#include "tetrixwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ TetrixWindow window;
+ window.show();
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ return app.exec();
+}
diff --git a/examples/widgets/tetrix/tetrix.pro b/examples/widgets/tetrix/tetrix.pro
new file mode 100644
index 0000000000..10b3f66435
--- /dev/null
+++ b/examples/widgets/tetrix/tetrix.pro
@@ -0,0 +1,18 @@
+HEADERS = tetrixboard.h \
+ tetrixpiece.h \
+ tetrixwindow.h
+SOURCES = main.cpp \
+ tetrixboard.cpp \
+ tetrixpiece.cpp \
+ tetrixwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tetrix
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tetrix.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tetrix
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C606
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/tetrix/tetrixboard.cpp b/examples/widgets/tetrix/tetrixboard.cpp
new file mode 100644
index 0000000000..1bb91ee3d7
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixboard.cpp
@@ -0,0 +1,408 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "tetrixboard.h"
+
+//! [0]
+TetrixBoard::TetrixBoard(QWidget *parent)
+ : QFrame(parent)
+{
+ setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ setFocusPolicy(Qt::StrongFocus);
+ isStarted = false;
+ isPaused = false;
+ clearBoard();
+
+ nextPiece.setRandomShape();
+}
+//! [0]
+
+//! [1]
+void TetrixBoard::setNextPieceLabel(QLabel *label)
+{
+ nextPieceLabel = label;
+}
+//! [1]
+
+//! [2]
+QSize TetrixBoard::sizeHint() const
+{
+ return QSize(BoardWidth * 15 + frameWidth() * 2,
+ BoardHeight * 15 + frameWidth() * 2);
+}
+
+QSize TetrixBoard::minimumSizeHint() const
+//! [2] //! [3]
+{
+ return QSize(BoardWidth * 5 + frameWidth() * 2,
+ BoardHeight * 5 + frameWidth() * 2);
+}
+//! [3]
+
+//! [4]
+void TetrixBoard::start()
+{
+ if (isPaused)
+ return;
+
+ isStarted = true;
+ isWaitingAfterLine = false;
+ numLinesRemoved = 0;
+ numPiecesDropped = 0;
+ score = 0;
+ level = 1;
+ clearBoard();
+
+ emit linesRemovedChanged(numLinesRemoved);
+ emit scoreChanged(score);
+ emit levelChanged(level);
+
+ newPiece();
+ timer.start(timeoutTime(), this);
+}
+//! [4]
+
+//! [5]
+void TetrixBoard::pause()
+{
+ if (!isStarted)
+ return;
+
+ isPaused = !isPaused;
+ if (isPaused) {
+ timer.stop();
+ } else {
+ timer.start(timeoutTime(), this);
+ }
+ update();
+//! [5] //! [6]
+}
+//! [6]
+
+//! [7]
+void TetrixBoard::paintEvent(QPaintEvent *event)
+{
+ QFrame::paintEvent(event);
+
+ QPainter painter(this);
+ QRect rect = contentsRect();
+//! [7]
+
+ if (isPaused) {
+ painter.drawText(rect, Qt::AlignCenter, tr("Pause"));
+ return;
+ }
+
+//! [8]
+ int boardTop = rect.bottom() - BoardHeight*squareHeight();
+
+ for (int i = 0; i < BoardHeight; ++i) {
+ for (int j = 0; j < BoardWidth; ++j) {
+ TetrixShape shape = shapeAt(j, BoardHeight - i - 1);
+ if (shape != NoShape)
+ drawSquare(painter, rect.left() + j * squareWidth(),
+ boardTop + i * squareHeight(), shape);
+ }
+//! [8] //! [9]
+ }
+//! [9]
+
+//! [10]
+ if (curPiece.shape() != NoShape) {
+ for (int i = 0; i < 4; ++i) {
+ int x = curX + curPiece.x(i);
+ int y = curY - curPiece.y(i);
+ drawSquare(painter, rect.left() + x * squareWidth(),
+ boardTop + (BoardHeight - y - 1) * squareHeight(),
+ curPiece.shape());
+ }
+//! [10] //! [11]
+ }
+//! [11] //! [12]
+}
+//! [12]
+
+//! [13]
+void TetrixBoard::keyPressEvent(QKeyEvent *event)
+{
+ if (!isStarted || isPaused || curPiece.shape() == NoShape) {
+ QFrame::keyPressEvent(event);
+ return;
+ }
+//! [13]
+
+//! [14]
+ switch (event->key()) {
+ case Qt::Key_Left:
+ tryMove(curPiece, curX - 1, curY);
+ break;
+ case Qt::Key_Right:
+ tryMove(curPiece, curX + 1, curY);
+ break;
+ case Qt::Key_Down:
+ tryMove(curPiece.rotatedRight(), curX, curY);
+ break;
+ case Qt::Key_Up:
+ tryMove(curPiece.rotatedLeft(), curX, curY);
+ break;
+ case Qt::Key_Space:
+ dropDown();
+ break;
+ case Qt::Key_D:
+ oneLineDown();
+ break;
+ default:
+ QFrame::keyPressEvent(event);
+ }
+//! [14]
+}
+
+//! [15]
+void TetrixBoard::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == timer.timerId()) {
+ if (isWaitingAfterLine) {
+ isWaitingAfterLine = false;
+ newPiece();
+ timer.start(timeoutTime(), this);
+ } else {
+ oneLineDown();
+ }
+ } else {
+ QFrame::timerEvent(event);
+//! [15] //! [16]
+ }
+//! [16] //! [17]
+}
+//! [17]
+
+//! [18]
+void TetrixBoard::clearBoard()
+{
+ for (int i = 0; i < BoardHeight * BoardWidth; ++i)
+ board[i] = NoShape;
+}
+//! [18]
+
+//! [19]
+void TetrixBoard::dropDown()
+{
+ int dropHeight = 0;
+ int newY = curY;
+ while (newY > 0) {
+ if (!tryMove(curPiece, curX, newY - 1))
+ break;
+ --newY;
+ ++dropHeight;
+ }
+ pieceDropped(dropHeight);
+//! [19] //! [20]
+}
+//! [20]
+
+//! [21]
+void TetrixBoard::oneLineDown()
+{
+ if (!tryMove(curPiece, curX, curY - 1))
+ pieceDropped(0);
+}
+//! [21]
+
+//! [22]
+void TetrixBoard::pieceDropped(int dropHeight)
+{
+ for (int i = 0; i < 4; ++i) {
+ int x = curX + curPiece.x(i);
+ int y = curY - curPiece.y(i);
+ shapeAt(x, y) = curPiece.shape();
+ }
+
+ ++numPiecesDropped;
+ if (numPiecesDropped % 25 == 0) {
+ ++level;
+ timer.start(timeoutTime(), this);
+ emit levelChanged(level);
+ }
+
+ score += dropHeight + 7;
+ emit scoreChanged(score);
+ removeFullLines();
+
+ if (!isWaitingAfterLine)
+ newPiece();
+//! [22] //! [23]
+}
+//! [23]
+
+//! [24]
+void TetrixBoard::removeFullLines()
+{
+ int numFullLines = 0;
+
+ for (int i = BoardHeight - 1; i >= 0; --i) {
+ bool lineIsFull = true;
+
+ for (int j = 0; j < BoardWidth; ++j) {
+ if (shapeAt(j, i) == NoShape) {
+ lineIsFull = false;
+ break;
+ }
+ }
+
+ if (lineIsFull) {
+//! [24] //! [25]
+ ++numFullLines;
+ for (int k = i; k < BoardHeight - 1; ++k) {
+ for (int j = 0; j < BoardWidth; ++j)
+ shapeAt(j, k) = shapeAt(j, k + 1);
+ }
+//! [25] //! [26]
+ for (int j = 0; j < BoardWidth; ++j)
+ shapeAt(j, BoardHeight - 1) = NoShape;
+ }
+//! [26] //! [27]
+ }
+//! [27]
+
+//! [28]
+ if (numFullLines > 0) {
+ numLinesRemoved += numFullLines;
+ score += 10 * numFullLines;
+ emit linesRemovedChanged(numLinesRemoved);
+ emit scoreChanged(score);
+
+ timer.start(500, this);
+ isWaitingAfterLine = true;
+ curPiece.setShape(NoShape);
+ update();
+ }
+//! [28] //! [29]
+}
+//! [29]
+
+//! [30]
+void TetrixBoard::newPiece()
+{
+ curPiece = nextPiece;
+ nextPiece.setRandomShape();
+ showNextPiece();
+ curX = BoardWidth / 2 + 1;
+ curY = BoardHeight - 1 + curPiece.minY();
+
+ if (!tryMove(curPiece, curX, curY)) {
+ curPiece.setShape(NoShape);
+ timer.stop();
+ isStarted = false;
+ }
+//! [30] //! [31]
+}
+//! [31]
+
+//! [32]
+void TetrixBoard::showNextPiece()
+{
+ if (!nextPieceLabel)
+ return;
+
+ int dx = nextPiece.maxX() - nextPiece.minX() + 1;
+ int dy = nextPiece.maxY() - nextPiece.minY() + 1;
+
+ QPixmap pixmap(dx * squareWidth(), dy * squareHeight());
+ QPainter painter(&pixmap);
+ painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background());
+
+ for (int i = 0; i < 4; ++i) {
+ int x = nextPiece.x(i) - nextPiece.minX();
+ int y = nextPiece.y(i) - nextPiece.minY();
+ drawSquare(painter, x * squareWidth(), y * squareHeight(),
+ nextPiece.shape());
+ }
+ nextPieceLabel->setPixmap(pixmap);
+//! [32] //! [33]
+}
+//! [33]
+
+//! [34]
+bool TetrixBoard::tryMove(const TetrixPiece &newPiece, int newX, int newY)
+{
+ for (int i = 0; i < 4; ++i) {
+ int x = newX + newPiece.x(i);
+ int y = newY - newPiece.y(i);
+ if (x < 0 || x >= BoardWidth || y < 0 || y >= BoardHeight)
+ return false;
+ if (shapeAt(x, y) != NoShape)
+ return false;
+ }
+//! [34]
+
+//! [35]
+ curPiece = newPiece;
+ curX = newX;
+ curY = newY;
+ update();
+ return true;
+}
+//! [35]
+
+//! [36]
+void TetrixBoard::drawSquare(QPainter &painter, int x, int y, TetrixShape shape)
+{
+ static const QRgb colorTable[8] = {
+ 0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
+ 0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00
+ };
+
+ QColor color = colorTable[int(shape)];
+ painter.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2,
+ color);
+
+ painter.setPen(color.light());
+ painter.drawLine(x, y + squareHeight() - 1, x, y);
+ painter.drawLine(x, y, x + squareWidth() - 1, y);
+
+ painter.setPen(color.dark());
+ painter.drawLine(x + 1, y + squareHeight() - 1,
+ x + squareWidth() - 1, y + squareHeight() - 1);
+ painter.drawLine(x + squareWidth() - 1, y + squareHeight() - 1,
+ x + squareWidth() - 1, y + 1);
+}
+//! [36]
diff --git a/examples/widgets/tetrix/tetrixboard.h b/examples/widgets/tetrix/tetrixboard.h
new file mode 100644
index 0000000000..4c06734469
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixboard.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TETRIXBOARD_H
+#define TETRIXBOARD_H
+
+#include <QBasicTimer>
+#include <QFrame>
+#include <QPointer>
+
+#include "tetrixpiece.h"
+
+QT_BEGIN_NAMESPACE
+class QLabel;
+QT_END_NAMESPACE
+
+//! [0]
+class TetrixBoard : public QFrame
+{
+ Q_OBJECT
+
+public:
+ TetrixBoard(QWidget *parent = 0);
+
+ void setNextPieceLabel(QLabel *label);
+ QSize sizeHint() const;
+ QSize minimumSizeHint() const;
+
+public slots:
+ void start();
+ void pause();
+
+signals:
+ void scoreChanged(int score);
+ void levelChanged(int level);
+ void linesRemovedChanged(int numLines);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+ void timerEvent(QTimerEvent *event);
+//! [0]
+
+//! [1]
+private:
+ enum { BoardWidth = 10, BoardHeight = 22 };
+
+ TetrixShape &shapeAt(int x, int y) { return board[(y * BoardWidth) + x]; }
+ int timeoutTime() { return 1000 / (1 + level); }
+ int squareWidth() { return contentsRect().width() / BoardWidth; }
+ int squareHeight() { return contentsRect().height() / BoardHeight; }
+ void clearBoard();
+ void dropDown();
+ void oneLineDown();
+ void pieceDropped(int dropHeight);
+ void removeFullLines();
+ void newPiece();
+ void showNextPiece();
+ bool tryMove(const TetrixPiece &newPiece, int newX, int newY);
+ void drawSquare(QPainter &painter, int x, int y, TetrixShape shape);
+
+ QBasicTimer timer;
+ QPointer<QLabel> nextPieceLabel;
+ bool isStarted;
+ bool isPaused;
+ bool isWaitingAfterLine;
+ TetrixPiece curPiece;
+ TetrixPiece nextPiece;
+ int curX;
+ int curY;
+ int numLinesRemoved;
+ int numPiecesDropped;
+ int score;
+ int level;
+ TetrixShape board[BoardWidth * BoardHeight];
+};
+//! [1]
+
+#endif
diff --git a/examples/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/tetrix/tetrixpiece.cpp
new file mode 100644
index 0000000000..c06c904a01
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixpiece.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+
+#include <stdlib.h>
+
+#include "tetrixpiece.h"
+
+//! [0]
+void TetrixPiece::setRandomShape()
+{
+ setShape(TetrixShape(qrand() % 7 + 1));
+}
+//! [0]
+
+//! [1]
+void TetrixPiece::setShape(TetrixShape shape)
+{
+ static const int coordsTable[8][4][2] = {
+ { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
+ { { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } },
+ { { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } },
+ { { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } },
+ { { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } },
+ { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } },
+ { { -1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } },
+ { { 1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } }
+ };
+
+ for (int i = 0; i < 4 ; i++) {
+ for (int j = 0; j < 2; ++j)
+ coords[i][j] = coordsTable[shape][i][j];
+ }
+ pieceShape = shape;
+//! [1] //! [2]
+}
+//! [2]
+
+//! [3]
+int TetrixPiece::minX() const
+{
+ int min = coords[0][0];
+ for (int i = 1; i < 4; ++i)
+ min = qMin(min, coords[i][0]);
+ return min;
+}
+
+int TetrixPiece::maxX() const
+//! [3] //! [4]
+{
+ int max = coords[0][0];
+ for (int i = 1; i < 4; ++i)
+ max = qMax(max, coords[i][0]);
+ return max;
+}
+//! [4]
+
+//! [5]
+int TetrixPiece::minY() const
+{
+ int min = coords[0][1];
+ for (int i = 1; i < 4; ++i)
+ min = qMin(min, coords[i][1]);
+ return min;
+}
+
+int TetrixPiece::maxY() const
+//! [5] //! [6]
+{
+ int max = coords[0][1];
+ for (int i = 1; i < 4; ++i)
+ max = qMax(max, coords[i][1]);
+ return max;
+}
+//! [6]
+
+//! [7]
+TetrixPiece TetrixPiece::rotatedLeft() const
+{
+ if (pieceShape == SquareShape)
+ return *this;
+
+ TetrixPiece result;
+ result.pieceShape = pieceShape;
+ for (int i = 0; i < 4; ++i) {
+ result.setX(i, y(i));
+ result.setY(i, -x(i));
+ }
+//! [7]
+ return result;
+}
+
+//! [9]
+TetrixPiece TetrixPiece::rotatedRight() const
+{
+ if (pieceShape == SquareShape)
+ return *this;
+
+ TetrixPiece result;
+ result.pieceShape = pieceShape;
+ for (int i = 0; i < 4; ++i) {
+ result.setX(i, -y(i));
+ result.setY(i, x(i));
+ }
+//! [9]
+ return result;
+}
diff --git a/examples/widgets/tetrix/tetrixpiece.h b/examples/widgets/tetrix/tetrixpiece.h
new file mode 100644
index 0000000000..c28db43f8a
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixpiece.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TETRIXPIECE_H
+#define TETRIXPIECE_H
+
+enum TetrixShape { NoShape, ZShape, SShape, LineShape, TShape, SquareShape,
+ LShape, MirroredLShape };
+
+//! [0]
+class TetrixPiece
+{
+public:
+ TetrixPiece() { setShape(NoShape); }
+
+ void setRandomShape();
+ void setShape(TetrixShape shape);
+
+ TetrixShape shape() const { return pieceShape; }
+ int x(int index) const { return coords[index][0]; }
+ int y(int index) const { return coords[index][1]; }
+ int minX() const;
+ int maxX() const;
+ int minY() const;
+ int maxY() const;
+ TetrixPiece rotatedLeft() const;
+ TetrixPiece rotatedRight() const;
+
+private:
+ void setX(int index, int x) { coords[index][0] = x; }
+ void setY(int index, int y) { coords[index][1] = y; }
+
+ TetrixShape pieceShape;
+ int coords[4][2];
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/tetrix/tetrixwindow.cpp
new file mode 100644
index 0000000000..fccb4beff1
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixwindow.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "tetrixboard.h"
+#include "tetrixwindow.h"
+
+//! [0]
+TetrixWindow::TetrixWindow()
+{
+ board = new TetrixBoard;
+//! [0]
+
+ nextPieceLabel = new QLabel;
+ nextPieceLabel->setFrameStyle(QFrame::Box | QFrame::Raised);
+ nextPieceLabel->setAlignment(Qt::AlignCenter);
+ board->setNextPieceLabel(nextPieceLabel);
+
+//! [1]
+ scoreLcd = new QLCDNumber(5);
+ scoreLcd->setSegmentStyle(QLCDNumber::Filled);
+//! [1]
+ levelLcd = new QLCDNumber(2);
+ levelLcd->setSegmentStyle(QLCDNumber::Filled);
+ linesLcd = new QLCDNumber(5);
+ linesLcd->setSegmentStyle(QLCDNumber::Filled);
+
+//! [2]
+ startButton = new QPushButton(tr("&Start"));
+ startButton->setFocusPolicy(Qt::NoFocus);
+ quitButton = new QPushButton(tr("&Quit"));
+ quitButton->setFocusPolicy(Qt::NoFocus);
+ pauseButton = new QPushButton(tr("&Pause"));
+//! [2] //! [3]
+ pauseButton->setFocusPolicy(Qt::NoFocus);
+//! [3] //! [4]
+
+ connect(startButton, SIGNAL(clicked()), board, SLOT(start()));
+//! [4] //! [5]
+ connect(quitButton , SIGNAL(clicked()), qApp, SLOT(quit()));
+ connect(pauseButton, SIGNAL(clicked()), board, SLOT(pause()));
+ connect(board, SIGNAL(scoreChanged(int)), scoreLcd, SLOT(display(int)));
+ connect(board, SIGNAL(levelChanged(int)), levelLcd, SLOT(display(int)));
+ connect(board, SIGNAL(linesRemovedChanged(int)),
+ linesLcd, SLOT(display(int)));
+//! [5]
+
+//! [6]
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(createLabel(tr("NEXT")), 0, 0);
+ layout->addWidget(nextPieceLabel, 1, 0);
+ layout->addWidget(createLabel(tr("LEVEL")), 2, 0);
+ layout->addWidget(levelLcd, 3, 0);
+ layout->addWidget(startButton, 4, 0);
+ layout->addWidget(board, 0, 1, 6, 1);
+ layout->addWidget(createLabel(tr("SCORE")), 0, 2);
+ layout->addWidget(scoreLcd, 1, 2);
+ layout->addWidget(createLabel(tr("LINES REMOVED")), 2, 2);
+ layout->addWidget(linesLcd, 3, 2);
+ layout->addWidget(quitButton, 4, 2);
+ layout->addWidget(pauseButton, 5, 2);
+ setLayout(layout);
+
+ setWindowTitle(tr("Tetrix"));
+ resize(550, 370);
+}
+//! [6]
+
+//! [7]
+QLabel *TetrixWindow::createLabel(const QString &text)
+{
+ QLabel *lbl = new QLabel(text);
+ lbl->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
+ return lbl;
+}
+//! [7]
+
diff --git a/examples/widgets/tetrix/tetrixwindow.h b/examples/widgets/tetrix/tetrixwindow.h
new file mode 100644
index 0000000000..6b0ec7b4f6
--- /dev/null
+++ b/examples/widgets/tetrix/tetrixwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TETRIXWINDOW_H
+#define TETRIXWINDOW_H
+
+#include <QFrame>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QLCDNumber;
+class QLabel;
+class QPushButton;
+QT_END_NAMESPACE
+class TetrixBoard;
+
+//! [0]
+class TetrixWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TetrixWindow();
+
+private:
+ QLabel *createLabel(const QString &text);
+
+ TetrixBoard *board;
+ QLabel *nextPieceLabel;
+ QLCDNumber *scoreLcd;
+ QLCDNumber *levelLcd;
+ QLCDNumber *linesLcd;
+ QPushButton *startButton;
+ QPushButton *quitButton;
+ QPushButton *pauseButton;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tooltips/images/circle.png b/examples/widgets/tooltips/images/circle.png
new file mode 100644
index 0000000000..dc392cb3f7
--- /dev/null
+++ b/examples/widgets/tooltips/images/circle.png
Binary files differ
diff --git a/examples/widgets/tooltips/images/square.png b/examples/widgets/tooltips/images/square.png
new file mode 100644
index 0000000000..c0fd2d540a
--- /dev/null
+++ b/examples/widgets/tooltips/images/square.png
Binary files differ
diff --git a/examples/widgets/tooltips/images/triangle.png b/examples/widgets/tooltips/images/triangle.png
new file mode 100644
index 0000000000..2ee15f8f1f
--- /dev/null
+++ b/examples/widgets/tooltips/images/triangle.png
Binary files differ
diff --git a/examples/widgets/tooltips/main.cpp b/examples/widgets/tooltips/main.cpp
new file mode 100644
index 0000000000..c31d90a1cd
--- /dev/null
+++ b/examples/widgets/tooltips/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "sortingbox.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(tooltips);
+
+ QApplication app(argc, argv);
+ qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+ SortingBox sortingBox;
+ sortingBox.show();
+ return app.exec();
+}
diff --git a/examples/widgets/tooltips/shapeitem.cpp b/examples/widgets/tooltips/shapeitem.cpp
new file mode 100644
index 0000000000..03b49be0ed
--- /dev/null
+++ b/examples/widgets/tooltips/shapeitem.cpp
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "shapeitem.h"
+
+//! [0]
+QPainterPath ShapeItem::path() const
+{
+ return myPath;
+}
+//! [0]
+
+//! [1]
+QPoint ShapeItem::position() const
+{
+ return myPosition;
+}
+//! [1]
+
+//! [2]
+QColor ShapeItem::color() const
+{
+ return myColor;
+}
+//! [2]
+
+//! [3]
+QString ShapeItem::toolTip() const
+{
+ return myToolTip;
+}
+//! [3]
+
+//! [4]
+void ShapeItem::setPath(const QPainterPath &path)
+{
+ myPath = path;
+}
+//! [4]
+
+//! [5]
+void ShapeItem::setToolTip(const QString &toolTip)
+{
+ myToolTip = toolTip;
+}
+//! [5]
+
+//! [6]
+void ShapeItem::setPosition(const QPoint &position)
+{
+ myPosition = position;
+}
+//! [6]
+
+//! [7]
+void ShapeItem::setColor(const QColor &color)
+{
+ myColor = color;
+}
+//! [7]
diff --git a/examples/widgets/tooltips/shapeitem.h b/examples/widgets/tooltips/shapeitem.h
new file mode 100644
index 0000000000..c79019abef
--- /dev/null
+++ b/examples/widgets/tooltips/shapeitem.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHAPEITEM_H
+#define SHAPEITEM_H
+
+#include <QColor>
+#include <QPainterPath>
+#include <QPoint>
+
+//! [0]
+class ShapeItem
+{
+public:
+ void setPath(const QPainterPath &path);
+ void setToolTip(const QString &toolTip);
+ void setPosition(const QPoint &position);
+ void setColor(const QColor &color);
+
+ QPainterPath path() const;
+ QPoint position() const;
+ QColor color() const;
+ QString toolTip() const;
+
+private:
+ QPainterPath myPath;
+ QPoint myPosition;
+ QColor myColor;
+ QString myToolTip;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/tooltips/sortingbox.cpp b/examples/widgets/tooltips/sortingbox.cpp
new file mode 100644
index 0000000000..083990c165
--- /dev/null
+++ b/examples/widgets/tooltips/sortingbox.cpp
@@ -0,0 +1,301 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include <stdlib.h>
+
+#include "sortingbox.h"
+
+//! [0]
+SortingBox::SortingBox()
+{
+//! [0] //! [1]
+ setMouseTracking(true);
+//! [1] //! [2]
+ setBackgroundRole(QPalette::Base);
+//! [2]
+
+ itemInMotion = 0;
+
+//! [3]
+ newCircleButton = createToolButton(tr("New Circle"),
+ QIcon(":/images/circle.png"),
+ SLOT(createNewCircle()));
+
+ newSquareButton = createToolButton(tr("New Square"),
+ QIcon(":/images/square.png"),
+ SLOT(createNewSquare()));
+
+ newTriangleButton = createToolButton(tr("New Triangle"),
+ QIcon(":/images/triangle.png"),
+ SLOT(createNewTriangle()));
+
+ circlePath.addEllipse(QRect(0, 0, 100, 100));
+ squarePath.addRect(QRect(0, 0, 100, 100));
+
+ qreal x = trianglePath.currentPosition().x();
+ qreal y = trianglePath.currentPosition().y();
+ trianglePath.moveTo(x + 120 / 2, y);
+ trianglePath.lineTo(0, 100);
+ trianglePath.lineTo(120, 100);
+ trianglePath.lineTo(x + 120 / 2, y);
+
+//! [3] //! [4]
+ setWindowTitle(tr("Tool Tips"));
+ resize(500, 300);
+
+ createShapeItem(circlePath, tr("Circle"), initialItemPosition(circlePath),
+ initialItemColor());
+ createShapeItem(squarePath, tr("Square"), initialItemPosition(squarePath),
+ initialItemColor());
+ createShapeItem(trianglePath, tr("Triangle"),
+ initialItemPosition(trianglePath), initialItemColor());
+}
+//! [4]
+
+//! [5]
+bool SortingBox::event(QEvent *event)
+{
+//! [5] //! [6]
+ if (event->type() == QEvent::ToolTip) {
+ QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
+ int index = itemAt(helpEvent->pos());
+ if (index != -1) {
+ QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
+ } else {
+ QToolTip::hideText();
+ event->ignore();
+ }
+
+ return true;
+ }
+ return QWidget::event(event);
+}
+//! [6]
+
+//! [7]
+void SortingBox::resizeEvent(QResizeEvent * /* event */)
+{
+ int margin = style()->pixelMetric(QStyle::PM_DefaultTopLevelMargin);
+ int x = width() - margin;
+ int y = height() - margin;
+
+ y = updateButtonGeometry(newCircleButton, x, y);
+ y = updateButtonGeometry(newSquareButton, x, y);
+ updateButtonGeometry(newTriangleButton, x, y);
+}
+//! [7]
+
+//! [8]
+void SortingBox::paintEvent(QPaintEvent * /* event */)
+{
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+ foreach (ShapeItem shapeItem, shapeItems) {
+//! [8] //! [9]
+ painter.translate(shapeItem.position());
+//! [9] //! [10]
+ painter.setBrush(shapeItem.color());
+ painter.drawPath(shapeItem.path());
+ painter.translate(-shapeItem.position());
+ }
+}
+//! [10]
+
+//! [11]
+void SortingBox::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ int index = itemAt(event->pos());
+ if (index != -1) {
+ itemInMotion = &shapeItems[index];
+ previousPosition = event->pos();
+ shapeItems.move(index, shapeItems.size() - 1);
+ update();
+ }
+ }
+}
+//! [11]
+
+//! [12]
+void SortingBox::mouseMoveEvent(QMouseEvent *event)
+{
+ if ((event->buttons() & Qt::LeftButton) && itemInMotion)
+ moveItemTo(event->pos());
+}
+//! [12]
+
+//! [13]
+void SortingBox::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton && itemInMotion) {
+ moveItemTo(event->pos());
+ itemInMotion = 0;
+ }
+}
+//! [13]
+
+//! [14]
+void SortingBox::createNewCircle()
+{
+ static int count = 1;
+ createShapeItem(circlePath, tr("Circle <%1>").arg(++count),
+ randomItemPosition(), randomItemColor());
+}
+//! [14]
+
+//! [15]
+void SortingBox::createNewSquare()
+{
+ static int count = 1;
+ createShapeItem(squarePath, tr("Square <%1>").arg(++count),
+ randomItemPosition(), randomItemColor());
+}
+//! [15]
+
+//! [16]
+void SortingBox::createNewTriangle()
+{
+ static int count = 1;
+ createShapeItem(trianglePath, tr("Triangle <%1>").arg(++count),
+ randomItemPosition(), randomItemColor());
+}
+//! [16]
+
+//! [17]
+int SortingBox::itemAt(const QPoint &pos)
+{
+ for (int i = shapeItems.size() - 1; i >= 0; --i) {
+ const ShapeItem &item = shapeItems[i];
+ if (item.path().contains(pos - item.position()))
+ return i;
+ }
+ return -1;
+}
+//! [17]
+
+//! [18]
+void SortingBox::moveItemTo(const QPoint &pos)
+{
+ QPoint offset = pos - previousPosition;
+ itemInMotion->setPosition(itemInMotion->position() + offset);
+//! [18] //! [19]
+ previousPosition = pos;
+ update();
+}
+//! [19]
+
+//! [20]
+int SortingBox::updateButtonGeometry(QToolButton *button, int x, int y)
+{
+ QSize size = button->sizeHint();
+ button->setGeometry(x - size.rwidth(), y - size.rheight(),
+ size.rwidth(), size.rheight());
+
+ return y - size.rheight()
+ - style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
+}
+//! [20]
+
+//! [21]
+void SortingBox::createShapeItem(const QPainterPath &path,
+ const QString &toolTip, const QPoint &pos,
+ const QColor &color)
+{
+ ShapeItem shapeItem;
+ shapeItem.setPath(path);
+ shapeItem.setToolTip(toolTip);
+ shapeItem.setPosition(pos);
+ shapeItem.setColor(color);
+ shapeItems.append(shapeItem);
+ update();
+}
+//! [21]
+
+//! [22]
+QToolButton *SortingBox::createToolButton(const QString &toolTip,
+ const QIcon &icon, const char *member)
+{
+ QToolButton *button = new QToolButton(this);
+ button->setToolTip(toolTip);
+ button->setIcon(icon);
+ button->setIconSize(QSize(32, 32));
+ connect(button, SIGNAL(clicked()), this, member);
+
+ return button;
+}
+//! [22]
+
+//! [23]
+QPoint SortingBox::initialItemPosition(const QPainterPath &path)
+{
+ int x;
+ int y = (height() - (int)path.controlPointRect().height()) / 2;
+ if (shapeItems.size() == 0)
+ x = ((3 * width()) / 2 - (int)path.controlPointRect().width()) / 2;
+ else
+ x = (width() / shapeItems.size()
+ - (int)path.controlPointRect().width()) / 2;
+
+ return QPoint(x, y);
+}
+//! [23]
+
+//! [24]
+QPoint SortingBox::randomItemPosition()
+{
+ return QPoint(qrand() % (width() - 120), qrand() % (height() - 120));
+}
+//! [24]
+
+//! [25]
+QColor SortingBox::initialItemColor()
+{
+ return QColor::fromHsv(((shapeItems.size() + 1) * 85) % 256, 255, 190);
+}
+//! [25]
+
+//! [26]
+QColor SortingBox::randomItemColor()
+{
+ return QColor::fromHsv(qrand() % 256, 255, 190);
+}
+//! [26]
diff --git a/examples/widgets/tooltips/sortingbox.h b/examples/widgets/tooltips/sortingbox.h
new file mode 100644
index 0000000000..0110a2310d
--- /dev/null
+++ b/examples/widgets/tooltips/sortingbox.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SORTINGBOX_H
+#define SORTINGBOX_H
+
+#include <QWidget>
+
+#include "shapeitem.h"
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QPoint;
+class QToolButton;
+QT_END_NAMESPACE
+
+//! [0]
+class SortingBox : public QWidget
+{
+ Q_OBJECT
+
+public:
+ SortingBox();
+
+protected:
+ bool event(QEvent *event);
+ void resizeEvent(QResizeEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+
+private slots:
+ void createNewCircle();
+ void createNewSquare();
+ void createNewTriangle();
+//! [0]
+
+//! [1]
+private:
+ int updateButtonGeometry(QToolButton *button, int x, int y);
+ void createShapeItem(const QPainterPath &path, const QString &toolTip,
+ const QPoint &pos, const QColor &color);
+ int itemAt(const QPoint &pos);
+ void moveItemTo(const QPoint &pos);
+ QPoint initialItemPosition(const QPainterPath &path);
+ QPoint randomItemPosition();
+ QColor initialItemColor();
+ QColor randomItemColor();
+ QToolButton *createToolButton(const QString &toolTip, const QIcon &icon,
+//! [1]
+ const char *member);
+
+//! [2]
+ QList<ShapeItem> shapeItems;
+ QPainterPath circlePath;
+ QPainterPath squarePath;
+ QPainterPath trianglePath;
+
+ QPoint previousPosition;
+ ShapeItem *itemInMotion;
+
+ QToolButton *newCircleButton;
+ QToolButton *newSquareButton;
+ QToolButton *newTriangleButton;
+};
+//! [2]
+
+#endif
diff --git a/examples/widgets/tooltips/tooltips.pro b/examples/widgets/tooltips/tooltips.pro
new file mode 100644
index 0000000000..4cbb6ca6ea
--- /dev/null
+++ b/examples/widgets/tooltips/tooltips.pro
@@ -0,0 +1,14 @@
+HEADERS = shapeitem.h \
+ sortingbox.h
+SOURCES = main.cpp \
+ shapeItem.cpp \
+ sortingbox.cpp
+RESOURCES = tooltips.qrc
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tooltips
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS tooltips.pro images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/tooltips
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/tooltips/tooltips.qrc b/examples/widgets/tooltips/tooltips.qrc
new file mode 100644
index 0000000000..dabc894e9b
--- /dev/null
+++ b/examples/widgets/tooltips/tooltips.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>images/circle.png</file>
+ <file>images/square.png</file>
+ <file>images/triangle.png</file>
+</qresource>
+</RCC>
diff --git a/examples/widgets/validators/ledoff.png b/examples/widgets/validators/ledoff.png
new file mode 100644
index 0000000000..8b1f2ed123
--- /dev/null
+++ b/examples/widgets/validators/ledoff.png
Binary files differ
diff --git a/examples/widgets/validators/ledon.png b/examples/widgets/validators/ledon.png
new file mode 100644
index 0000000000..601c34d5a8
--- /dev/null
+++ b/examples/widgets/validators/ledon.png
Binary files differ
diff --git a/examples/widgets/validators/ledwidget.cpp b/examples/widgets/validators/ledwidget.cpp
new file mode 100644
index 0000000000..c63321ec63
--- /dev/null
+++ b/examples/widgets/validators/ledwidget.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "ledwidget.h"
+
+LEDWidget::LEDWidget(QWidget *parent)
+ : QLabel(parent), onPixmap(":/ledon.png"), offPixmap(":/ledoff.png")
+{
+ setPixmap(offPixmap);
+ flashTimer.setInterval(200);
+ flashTimer.setSingleShot(true);
+ connect(&flashTimer, SIGNAL(timeout()), this, SLOT(extinguish()));
+};
+
+void LEDWidget::extinguish()
+{
+ setPixmap(offPixmap);
+}
+
+void LEDWidget::flash()
+{
+ setPixmap(onPixmap);
+ flashTimer.start();
+}
+
diff --git a/examples/widgets/validators/ledwidget.h b/examples/widgets/validators/ledwidget.h
new file mode 100644
index 0000000000..33c477dcbd
--- /dev/null
+++ b/examples/widgets/validators/ledwidget.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LEDWIDGET_H
+#define LEDWIDGET_H
+
+#include <QLabel>
+#include <QPixmap>
+#include <QTimer>
+
+class LEDWidget : public QLabel
+{
+ Q_OBJECT
+public:
+ LEDWidget(QWidget *parent = 0);
+public slots:
+ void flash();
+
+private slots:
+ void extinguish();
+
+private:
+ QPixmap onPixmap, offPixmap;
+ QTimer flashTimer;
+};
+
+#endif // LEDWIDGET_H
diff --git a/examples/widgets/validators/localeselector.cpp b/examples/widgets/validators/localeselector.cpp
new file mode 100644
index 0000000000..bcf5d91ba9
--- /dev/null
+++ b/examples/widgets/validators/localeselector.cpp
@@ -0,0 +1,312 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "localeselector.h"
+#include <QLocale>
+
+struct SupportedLocale
+{
+ int lang, country;
+};
+
+const SupportedLocale SUPPORTED_LOCALES[] = {
+ { 1, 0 }, // C/AnyCountry
+ { 3, 69 }, // Afan/Ethiopia
+ { 3, 111 }, // Afan/Kenya
+ { 4, 59 }, // Afar/Djibouti
+ { 4, 67 }, // Afar/Eritrea
+ { 4, 69 }, // Afar/Ethiopia
+ { 5, 195 }, // Afrikaans/SouthAfrica
+ { 5, 148 }, // Afrikaans/Namibia
+ { 6, 2 }, // Albanian/Albania
+ { 7, 69 }, // Amharic/Ethiopia
+ { 8, 186 }, // Arabic/SaudiArabia
+ { 8, 3 }, // Arabic/Algeria
+ { 8, 17 }, // Arabic/Bahrain
+ { 8, 64 }, // Arabic/Egypt
+ { 8, 103 }, // Arabic/Iraq
+ { 8, 109 }, // Arabic/Jordan
+ { 8, 115 }, // Arabic/Kuwait
+ { 8, 119 }, // Arabic/Lebanon
+ { 8, 122 }, // Arabic/LibyanArabJamahiriya
+ { 8, 145 }, // Arabic/Morocco
+ { 8, 162 }, // Arabic/Oman
+ { 8, 175 }, // Arabic/Qatar
+ { 8, 201 }, // Arabic/Sudan
+ { 8, 207 }, // Arabic/SyrianArabRepublic
+ { 8, 216 }, // Arabic/Tunisia
+ { 8, 223 }, // Arabic/UnitedArabEmirates
+ { 8, 237 }, // Arabic/Yemen
+ { 9, 11 }, // Armenian/Armenia
+ { 10, 100 }, // Assamese/India
+ { 12, 15 }, // Azerbaijani/Azerbaijan
+ { 14, 197 }, // Basque/Spain
+ { 15, 18 }, // Bengali/Bangladesh
+ { 15, 100 }, // Bengali/India
+ { 16, 25 }, // Bhutani/Bhutan
+ { 20, 33 }, // Bulgarian/Bulgaria
+ { 22, 20 }, // Byelorussian/Belarus
+ { 23, 36 }, // Cambodian/Cambodia
+ { 24, 197 }, // Catalan/Spain
+ { 25, 44 }, // Chinese/China
+ { 25, 97 }, // Chinese/HongKong
+ { 25, 126 }, // Chinese/Macau
+ { 25, 190 }, // Chinese/Singapore
+ { 25, 208 }, // Chinese/Taiwan
+ { 27, 54 }, // Croatian/Croatia
+ { 28, 57 }, // Czech/CzechRepublic
+ { 29, 58 }, // Danish/Denmark
+ { 30, 151 }, // Dutch/Netherlands
+ { 30, 21 }, // Dutch/Belgium
+ { 31, 225 }, // English/UnitedStates
+ { 31, 4 }, // English/AmericanSamoa
+ { 31, 13 }, // English/Australia
+ { 31, 21 }, // English/Belgium
+ { 31, 22 }, // English/Belize
+ { 31, 28 }, // English/Botswana
+ { 31, 38 }, // English/Canada
+ { 31, 89 }, // English/Guam
+ { 31, 97 }, // English/HongKong
+ { 31, 100 }, // English/India
+ { 31, 104 }, // English/Ireland
+ { 31, 107 }, // English/Jamaica
+ { 31, 133 }, // English/Malta
+ { 31, 134 }, // English/MarshallIslands
+ { 31, 148 }, // English/Namibia
+ { 31, 154 }, // English/NewZealand
+ { 31, 160 }, // English/NorthernMarianaIslands
+ { 31, 163 }, // English/Pakistan
+ { 31, 170 }, // English/Philippines
+ { 31, 190 }, // English/Singapore
+ { 31, 195 }, // English/SouthAfrica
+ { 31, 215 }, // English/TrinidadAndTobago
+ { 31, 224 }, // English/UnitedKingdom
+ { 31, 226 }, // English/UnitedStatesMinorOutlyingIslands
+ { 31, 234 }, // English/USVirginIslands
+ { 31, 240 }, // English/Zimbabwe
+ { 33, 68 }, // Estonian/Estonia
+ { 34, 71 }, // Faroese/FaroeIslands
+ { 36, 73 }, // Finnish/Finland
+ { 37, 74 }, // French/France
+ { 37, 21 }, // French/Belgium
+ { 37, 38 }, // French/Canada
+ { 37, 125 }, // French/Luxembourg
+ { 37, 142 }, // French/Monaco
+ { 37, 206 }, // French/Switzerland
+ { 40, 197 }, // Galician/Spain
+ { 41, 81 }, // Georgian/Georgia
+ { 42, 82 }, // German/Germany
+ { 42, 14 }, // German/Austria
+ { 42, 21 }, // German/Belgium
+ { 42, 123 }, // German/Liechtenstein
+ { 42, 125 }, // German/Luxembourg
+ { 42, 206 }, // German/Switzerland
+ { 43, 85 }, // Greek/Greece
+ { 43, 56 }, // Greek/Cyprus
+ { 44, 86 }, // Greenlandic/Greenland
+ { 46, 100 }, // Gujarati/India
+ { 47, 83 }, // Hausa/Ghana
+ { 47, 156 }, // Hausa/Niger
+ { 47, 157 }, // Hausa/Nigeria
+ { 48, 105 }, // Hebrew/Israel
+ { 49, 100 }, // Hindi/India
+ { 50, 98 }, // Hungarian/Hungary
+ { 51, 99 }, // Icelandic/Iceland
+ { 52, 101 }, // Indonesian/Indonesia
+ { 57, 104 }, // Irish/Ireland
+ { 58, 106 }, // Italian/Italy
+ { 58, 206 }, // Italian/Switzerland
+ { 59, 108 }, // Japanese/Japan
+ { 61, 100 }, // Kannada/India
+ { 63, 110 }, // Kazakh/Kazakhstan
+ { 64, 179 }, // Kinyarwanda/Rwanda
+ { 65, 116 }, // Kirghiz/Kyrgyzstan
+ { 66, 114 }, // Korean/RepublicOfKorea
+ { 67, 102 }, // Kurdish/Iran
+ { 67, 103 }, // Kurdish/Iraq
+ { 67, 207 }, // Kurdish/SyrianArabRepublic
+ { 67, 217 }, // Kurdish/Turkey
+ { 69, 117 }, // Laothian/Lao
+ { 71, 118 }, // Latvian/Latvia
+ { 72, 49 }, // Lingala/DemocraticRepublicOfCongo
+ { 72, 50 }, // Lingala/PeoplesRepublicOfCongo
+ { 73, 124 }, // Lithuanian/Lithuania
+ { 74, 127 }, // Macedonian/Macedonia
+ { 76, 130 }, // Malay/Malaysia
+ { 76, 32 }, // Malay/BruneiDarussalam
+ { 77, 100 }, // Malayalam/India
+ { 78, 133 }, // Maltese/Malta
+ { 80, 100 }, // Marathi/India
+ { 82, 143 }, // Mongolian/Mongolia
+ { 84, 150 }, // Nepali/Nepal
+ { 85, 161 }, // Norwegian/Norway
+ { 87, 100 }, // Oriya/India
+ { 88, 1 }, // Pashto/Afghanistan
+ { 89, 102 }, // Persian/Iran
+ { 89, 1 }, // Persian/Afghanistan
+ { 90, 172 }, // Polish/Poland
+ { 91, 173 }, // Portuguese/Portugal
+ { 91, 30 }, // Portuguese/Brazil
+ { 92, 100 }, // Punjabi/India
+ { 92, 163 }, // Punjabi/Pakistan
+ { 95, 177 }, // Romanian/Romania
+ { 96, 178 }, // Russian/RussianFederation
+ { 96, 222 }, // Russian/Ukraine
+ { 99, 100 }, // Sanskrit/India
+ { 100, 241 }, // Serbian/SerbiaAndMontenegro
+ { 100, 27 }, // Serbian/BosniaAndHerzegowina
+ { 100, 238 }, // Serbian/Yugoslavia
+ { 101, 241 }, // SerboCroatian/SerbiaAndMontenegro
+ { 101, 27 }, // SerboCroatian/BosniaAndHerzegowina
+ { 101, 238 }, // SerboCroatian/Yugoslavia
+ { 102, 195 }, // Sesotho/SouthAfrica
+ { 103, 195 }, // Setswana/SouthAfrica
+ { 107, 195 }, // Siswati/SouthAfrica
+ { 108, 191 }, // Slovak/Slovakia
+ { 109, 192 }, // Slovenian/Slovenia
+ { 110, 194 }, // Somali/Somalia
+ { 110, 59 }, // Somali/Djibouti
+ { 110, 69 }, // Somali/Ethiopia
+ { 110, 111 }, // Somali/Kenya
+ { 111, 197 }, // Spanish/Spain
+ { 111, 10 }, // Spanish/Argentina
+ { 111, 26 }, // Spanish/Bolivia
+ { 111, 43 }, // Spanish/Chile
+ { 111, 47 }, // Spanish/Colombia
+ { 111, 52 }, // Spanish/CostaRica
+ { 111, 61 }, // Spanish/DominicanRepublic
+ { 111, 63 }, // Spanish/Ecuador
+ { 111, 65 }, // Spanish/ElSalvador
+ { 111, 90 }, // Spanish/Guatemala
+ { 111, 96 }, // Spanish/Honduras
+ { 111, 139 }, // Spanish/Mexico
+ { 111, 155 }, // Spanish/Nicaragua
+ { 111, 166 }, // Spanish/Panama
+ { 111, 168 }, // Spanish/Paraguay
+ { 111, 169 }, // Spanish/Peru
+ { 111, 174 }, // Spanish/PuertoRico
+ { 111, 225 }, // Spanish/UnitedStates
+ { 111, 227 }, // Spanish/Uruguay
+ { 111, 231 }, // Spanish/Venezuela
+ { 113, 111 }, // Swahili/Kenya
+ { 113, 210 }, // Swahili/Tanzania
+ { 114, 205 }, // Swedish/Sweden
+ { 114, 73 }, // Swedish/Finland
+ { 116, 209 }, // Tajik/Tajikistan
+ { 117, 100 }, // Tamil/India
+ { 118, 178 }, // Tatar/RussianFederation
+ { 119, 100 }, // Telugu/India
+ { 120, 211 }, // Thai/Thailand
+ { 122, 67 }, // Tigrinya/Eritrea
+ { 122, 69 }, // Tigrinya/Ethiopia
+ { 124, 195 }, // Tsonga/SouthAfrica
+ { 125, 217 }, // Turkish/Turkey
+ { 129, 222 }, // Ukrainian/Ukraine
+ { 130, 100 }, // Urdu/India
+ { 130, 163 }, // Urdu/Pakistan
+ { 131, 228 }, // Uzbek/Uzbekistan
+ { 131, 1 }, // Uzbek/Afghanistan
+ { 132, 232 }, // Vietnamese/VietNam
+ { 134, 224 }, // Welsh/UnitedKingdom
+ { 136, 195 }, // Xhosa/SouthAfrica
+ { 138, 157 }, // Yoruba/Nigeria
+ { 140, 195 }, // Zulu/SouthAfrica
+ { 141, 161 }, // Nynorsk/Norway
+ { 142, 27 }, // Bosnian/BosniaAndHerzegowina
+ { 143, 131 }, // Divehi/Maldives
+ { 144, 224 }, // Manx/UnitedKingdom
+ { 145, 224 }, // Cornish/UnitedKingdom
+ { 146, 83 }, // Akan/Ghana
+ { 147, 100 }, // Konkani/India
+ { 148, 83 }, // Ga/Ghana
+ { 149, 157 }, // Igbo/Nigeria
+ { 150, 111 }, // Kamba/Kenya
+ { 151, 207 }, // Syriac/SyrianArabRepublic
+ { 152, 67 }, // Blin/Eritrea
+ { 153, 67 }, // Geez/Eritrea
+ { 153, 69 }, // Geez/Ethiopia
+ { 154, 157 }, // Koro/Nigeria
+ { 155, 69 }, // Sidamo/Ethiopia
+ { 156, 157 }, // Atsam/Nigeria
+ { 157, 67 }, // Tigre/Eritrea
+ { 158, 157 }, // Jju/Nigeria
+ { 159, 106 }, // Friulian/Italy
+ { 160, 195 }, // Venda/SouthAfrica
+ { 161, 83 }, // Ewe/Ghana
+ { 161, 212 }, // Ewe/Togo
+ { 163, 225 }, // Hawaiian/UnitedStates
+ { 164, 157 }, // Tyap/Nigeria
+ { 165, 129 } // Chewa/Malawi
+};
+
+const int SUPPORTED_LOCALES_COUNT = sizeof(SUPPORTED_LOCALES)/sizeof(SupportedLocale);
+
+typedef QPair<int, int> IntPair;
+Q_DECLARE_METATYPE(SupportedLocale)
+
+LocaleSelector::LocaleSelector(QWidget *parent)
+ : QComboBox(parent)
+{
+ int curIndex = -1;
+ QLocale curLocale;
+
+ for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) {
+ const SupportedLocale &l = SUPPORTED_LOCALES[i];
+ if (l.lang == curLocale.language() && l.country == curLocale.country())
+ curIndex = i;
+ QString text = QLocale::languageToString(QLocale::Language(l.lang))
+ + QLatin1Char('/')
+ + QLocale::countryToString(QLocale::Country(l.country));
+ addItem(text, QVariant::fromValue(l));
+ }
+
+ setCurrentIndex(curIndex);
+
+ connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int)));
+}
+
+void LocaleSelector::emitLocaleSelected(int index)
+{
+ QVariant v = itemData(index);
+ if (!v.isValid())
+ return;
+ SupportedLocale l = qvariant_cast<SupportedLocale>(v);
+ emit localeSelected(QLocale(QLocale::Language(l.lang), QLocale::Country(l.country)));
+}
diff --git a/examples/widgets/validators/localeselector.h b/examples/widgets/validators/localeselector.h
new file mode 100644
index 0000000000..ea09224f75
--- /dev/null
+++ b/examples/widgets/validators/localeselector.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LOCALESELECTOR_H
+#define LOCALESELECTOR_H
+
+#include <QComboBox>
+
+class LocaleSelector : public QComboBox
+{
+ Q_OBJECT
+
+public:
+ LocaleSelector(QWidget *parent = 0);
+
+signals:
+ void localeSelected(const QLocale &locale);
+
+private slots:
+ void emitLocaleSelected(int index);
+};
+
+#endif //LOCALESELECTOR_H
diff --git a/examples/widgets/validators/main.cpp b/examples/widgets/validators/main.cpp
new file mode 100644
index 0000000000..5e5765e957
--- /dev/null
+++ b/examples/widgets/validators/main.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qdebug.h>
+#include <QApplication>
+#include <QLineEdit>
+#include <QValidator>
+
+#include "ui_validators.h"
+
+class ValidatorWidget : public QWidget, public Ui::ValidatorsForm
+{
+ Q_OBJECT
+public:
+ ValidatorWidget(QWidget *parent = 0);
+
+private slots:
+ void updateValidator();
+ void updateDoubleValidator();
+ void _setLocale(const QLocale &l) { setLocale(l); updateValidator(); updateDoubleValidator(); }
+
+private:
+ QIntValidator *validator;
+ QDoubleValidator *doubleValidator;
+};
+
+ValidatorWidget::ValidatorWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setupUi(this);
+
+ connect(localeSelector, SIGNAL(localeSelected(QLocale)), this, SLOT(_setLocale(QLocale)));
+
+ connect(minVal, SIGNAL(editingFinished()), this, SLOT(updateValidator()));
+ connect(maxVal, SIGNAL(editingFinished()), this, SLOT(updateValidator()));
+ connect(editor, SIGNAL(editingFinished()), ledWidget, SLOT(flash()));
+
+ connect(doubleMaxVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator()));
+ connect(doubleMinVal, SIGNAL(editingFinished()), this, SLOT(updateDoubleValidator()));
+ connect(doubleDecimals, SIGNAL(valueChanged(int)), this, SLOT(updateDoubleValidator()));
+ connect(doubleFormat, SIGNAL(activated(int)), this, SLOT(updateDoubleValidator()));
+ connect(doubleEditor, SIGNAL(editingFinished()), doubleLedWidget, SLOT(flash()));
+
+ validator = 0;
+ doubleValidator = 0;
+ updateValidator();
+ updateDoubleValidator();
+};
+
+void ValidatorWidget::updateValidator()
+{
+ QIntValidator *v = new QIntValidator(minVal->value(), maxVal->value(), this);
+ v->setLocale(locale());
+ editor->setValidator(v);
+ delete validator;
+ validator = v;
+
+ QString s = editor->text();
+ int i = 0;
+ if (validator->validate(s, i) == QValidator::Invalid) {
+ editor->clear();
+ } else {
+ editor->setText(s);
+ }
+}
+
+void ValidatorWidget::updateDoubleValidator()
+{
+ QDoubleValidator *v
+ = new QDoubleValidator(doubleMinVal->value(), doubleMaxVal->value(),
+ doubleDecimals->value(), this);
+ v->setNotation(static_cast<QDoubleValidator::Notation>(doubleFormat->currentIndex()));
+ v->setLocale(locale());
+ doubleEditor->setValidator(v);
+ delete doubleValidator;
+ doubleValidator = v;
+
+ QString s = doubleEditor->text();
+ int i = 0;
+ if (doubleValidator->validate(s, i) == QValidator::Invalid) {
+ doubleEditor->clear();
+ } else {
+ doubleEditor->setText(s);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(validators);
+
+ QApplication app(argc, argv);
+
+ ValidatorWidget w;
+ w.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/examples/widgets/validators/validators.pro b/examples/widgets/validators/validators.pro
new file mode 100644
index 0000000000..7e1cb1eea7
--- /dev/null
+++ b/examples/widgets/validators/validators.pro
@@ -0,0 +1,23 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue Nov 28 13:20:04 2006
+######################################################################
+
+TEMPLATE = app
+TARGET = validators
+DEPENDPATH += .
+INCLUDEPATH += .
+
+FORMS += validators.ui
+RESOURCES += validators.qrc
+
+# Input
+SOURCES += main.cpp ledwidget.cpp localeselector.cpp
+HEADERS += ledwidget.h localeselector.h
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/validators
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.png
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/validators
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/validators/validators.qrc b/examples/widgets/validators/validators.qrc
new file mode 100644
index 0000000000..94874317a8
--- /dev/null
+++ b/examples/widgets/validators/validators.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/" >
+ <file>ledoff.png</file>
+ <file>ledon.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/validators/validators.ui b/examples/widgets/validators/validators.ui
new file mode 100644
index 0000000000..cd984e6b97
--- /dev/null
+++ b/examples/widgets/validators/validators.ui
@@ -0,0 +1,468 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ValidatorsForm</class>
+ <widget class="QWidget" name="ValidatorsForm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>526</width>
+ <height>443</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Validators</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="LocaleSelector" name="localeSelector"/>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>QIntValidator</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Min:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QSpinBox" name="minVal">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <number>-1000000</number>
+ </property>
+ <property name="maximum">
+ <number>1000000</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Max:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="maxVal">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <number>-1000000</number>
+ </property>
+ <property name="maximum">
+ <number>1000000</number>
+ </property>
+ <property name="value">
+ <number>1000</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QFrame" name="frame">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <widget class="LEDWidget" name="ledWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="pixmap">
+ <pixmap resource="validators.qrc">:/ledoff.png</pixmap>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>editingFinished()</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="editor"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>QDoubleValidator</string>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QGridLayout">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Min:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDoubleSpinBox" name="doubleMinVal">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <double>-100000.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>100000.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>0.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Format:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QComboBox" name="doubleFormat">
+ <item>
+ <property name="text">
+ <string>Standard</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Scientific</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Max:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDoubleSpinBox" name="doubleMaxVal">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimum">
+ <double>-100000.000000000000000</double>
+ </property>
+ <property name="maximum">
+ <double>100000.000000000000000</double>
+ </property>
+ <property name="value">
+ <double>1000.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Decimals:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QSpinBox" name="doubleDecimals">
+ <property name="value">
+ <number>2</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QFrame" name="frame_2">
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>9</number>
+ </property>
+ <item>
+ <widget class="LEDWidget" name="doubleLedWidget">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="pixmap">
+ <pixmap resource="validators.qrc">:/ledoff.png</pixmap>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>editingFinished()</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="doubleEditor"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>111</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>Quit</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>LEDWidget</class>
+ <extends>QLabel</extends>
+ <header>ledwidget.h</header>
+ </customwidget>
+ <customwidget>
+ <class>LocaleSelector</class>
+ <extends>QComboBox</extends>
+ <header>localeselector.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="validators.qrc"/>
+ </resources>
+ <connections>
+ <connection>
+ <sender>pushButton</sender>
+ <signal>clicked()</signal>
+ <receiver>ValidatorsForm</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>94</x>
+ <y>274</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>131</x>
+ <y>260</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro
new file mode 100644
index 0000000000..72652e3bc5
--- /dev/null
+++ b/examples/widgets/widgets.pro
@@ -0,0 +1,43 @@
+TEMPLATE = subdirs
+SUBDIRS = analogclock \
+ calculator \
+ calendarwidget \
+ charactermap \
+ codeeditor \
+ digitalclock \
+ groupbox \
+ icons \
+ imageviewer \
+ lineedits \
+ movie \
+ scribble \
+ shapedclock \
+ sliders \
+ spinboxes \
+ stylesheet \
+ tablet \
+ tetrix \
+ tooltips \
+ validators \
+ wiggly \
+ windowflags
+
+symbian: SUBDIRS = \
+ analogclock \
+ calculator \
+ calendarwidget \
+ lineedits \
+ shapedclock \
+ tetrix \
+ wiggly \
+ softkeys
+
+contains(styles, motif): SUBDIRS += styles
+
+# 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
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/widgets/wiggly/dialog.cpp b/examples/widgets/wiggly/dialog.cpp
new file mode 100644
index 0000000000..a5b376143c
--- /dev/null
+++ b/examples/widgets/wiggly/dialog.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "dialog.h"
+#include "wigglywidget.h"
+
+//! [0]
+Dialog::Dialog(QWidget *parent, bool smallScreen)
+ : QDialog(parent)
+{
+ WigglyWidget *wigglyWidget = new WigglyWidget;
+ QLineEdit *lineEdit = new QLineEdit;
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(wigglyWidget);
+ layout->addWidget(lineEdit);
+ setLayout(layout);
+
+#ifdef QT_SOFTKEYS_ENABLED
+ QAction *exitAction = new QAction(tr("Exit"), this);
+ exitAction->setSoftKeyRole(QAction::NegativeSoftKey);
+ connect (exitAction, SIGNAL(triggered()),this, SLOT(close()));
+ addAction (exitAction);
+
+ Qt::WindowFlags flags = windowFlags();
+ flags |= Qt::WindowSoftkeysVisibleHint;
+ setWindowFlags(flags);
+#endif
+
+ connect(lineEdit, SIGNAL(textChanged(QString)),
+ wigglyWidget, SLOT(setText(QString)));
+ if (!smallScreen){
+ lineEdit->setText(tr("Hello world!"));
+ }
+ else{
+ lineEdit->setText(tr("Hello!"));
+ }
+ setWindowTitle(tr("Wiggly"));
+ resize(360, 145);
+}
+//! [0]
diff --git a/examples/widgets/wiggly/dialog.h b/examples/widgets/wiggly/dialog.h
new file mode 100644
index 0000000000..aa12a375fe
--- /dev/null
+++ b/examples/widgets/wiggly/dialog.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DIALOG_H
+#define DIALOG_H
+
+#include <QDialog>
+
+//! [0]
+class Dialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ Dialog(QWidget *parent = 0, bool smallScreen = false);
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/wiggly/main.cpp b/examples/widgets/wiggly/main.cpp
new file mode 100644
index 0000000000..91cd1b8c4b
--- /dev/null
+++ b/examples/widgets/wiggly/main.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "dialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ bool smallScreen = QApplication::arguments().contains("-small-screen");
+
+ Dialog dialog(0, smallScreen);
+
+ if (!smallScreen)
+ dialog.show();
+ else
+ dialog.showFullScreen();
+ return app.exec();
+}
diff --git a/examples/widgets/wiggly/wiggly.pro b/examples/widgets/wiggly/wiggly.pro
new file mode 100644
index 0000000000..ce8b514eda
--- /dev/null
+++ b/examples/widgets/wiggly/wiggly.pro
@@ -0,0 +1,16 @@
+HEADERS = wigglywidget.h \
+ dialog.h
+SOURCES = wigglywidget.cpp \
+ dialog.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/wiggly
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS wiggly.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/wiggly
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C607
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/widgets/wiggly/wigglywidget.cpp b/examples/widgets/wiggly/wigglywidget.cpp
new file mode 100644
index 0000000000..56a026ade7
--- /dev/null
+++ b/examples/widgets/wiggly/wigglywidget.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "wigglywidget.h"
+
+//! [0]
+WigglyWidget::WigglyWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ setBackgroundRole(QPalette::Midlight);
+ setAutoFillBackground(true);
+
+ QFont newFont = font();
+ newFont.setPointSize(newFont.pointSize() + 20);
+ setFont(newFont);
+
+ step = 0;
+ timer.start(60, this);
+}
+//! [0]
+
+//! [1]
+void WigglyWidget::paintEvent(QPaintEvent * /* event */)
+//! [1] //! [2]
+{
+ static const int sineTable[16] = {
+ 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38
+ };
+
+ QFontMetrics metrics(font());
+ int x = (width() - metrics.width(text)) / 2;
+ int y = (height() + metrics.ascent() - metrics.descent()) / 2;
+ QColor color;
+//! [2]
+
+//! [3]
+ QPainter painter(this);
+//! [3] //! [4]
+ for (int i = 0; i < text.size(); ++i) {
+ int index = (step + i) % 16;
+ color.setHsv((15 - index) * 16, 255, 191);
+ painter.setPen(color);
+ painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400),
+ QString(text[i]));
+ x += metrics.width(text[i]);
+ }
+}
+//! [4]
+
+//! [5]
+void WigglyWidget::timerEvent(QTimerEvent *event)
+//! [5] //! [6]
+{
+ if (event->timerId() == timer.timerId()) {
+ ++step;
+ update();
+ } else {
+ QWidget::timerEvent(event);
+ }
+//! [6]
+}
diff --git a/examples/widgets/wiggly/wigglywidget.h b/examples/widgets/wiggly/wigglywidget.h
new file mode 100644
index 0000000000..7e8d8b5c39
--- /dev/null
+++ b/examples/widgets/wiggly/wigglywidget.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WIGGLYWIDGET_H
+#define WIGGLYWIDGET_H
+
+#include <QBasicTimer>
+#include <QWidget>
+
+//! [0]
+class WigglyWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ WigglyWidget(QWidget *parent = 0);
+
+public slots:
+ void setText(const QString &newText) { text = newText; }
+
+protected:
+ void paintEvent(QPaintEvent *event);
+ void timerEvent(QTimerEvent *event);
+
+private:
+ QBasicTimer timer;
+ QString text;
+ int step;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/windowflags/controllerwindow.cpp b/examples/widgets/windowflags/controllerwindow.cpp
new file mode 100644
index 0000000000..c52e2b27c3
--- /dev/null
+++ b/examples/widgets/windowflags/controllerwindow.cpp
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "controllerwindow.h"
+
+//! [0]
+ControllerWindow::ControllerWindow()
+{
+ previewWindow = new PreviewWindow(this);
+
+ createTypeGroupBox();
+ createHintsGroupBox();
+
+ quitButton = new QPushButton(tr("&Quit"));
+ connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
+
+ QHBoxLayout *bottomLayout = new QHBoxLayout;
+ bottomLayout->addStretch();
+ bottomLayout->addWidget(quitButton);
+
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ mainLayout->addWidget(typeGroupBox);
+ mainLayout->addWidget(hintsGroupBox);
+ mainLayout->addLayout(bottomLayout);
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Window Flags"));
+ updatePreview();
+}
+//! [0]
+
+//! [1]
+void ControllerWindow::updatePreview()
+{
+ Qt::WindowFlags flags = 0;
+
+ if (windowRadioButton->isChecked()) {
+ flags = Qt::Window;
+ } else if (dialogRadioButton->isChecked()) {
+ flags = Qt::Dialog;
+ } else if (sheetRadioButton->isChecked()) {
+ flags = Qt::Sheet;
+ } else if (drawerRadioButton->isChecked()) {
+ flags = Qt::Drawer;
+ } else if (popupRadioButton->isChecked()) {
+ flags = Qt::Popup;
+ } else if (toolRadioButton->isChecked()) {
+ flags = Qt::Tool;
+ } else if (toolTipRadioButton->isChecked()) {
+ flags = Qt::ToolTip;
+ } else if (splashScreenRadioButton->isChecked()) {
+ flags = Qt::SplashScreen;
+//! [1] //! [2]
+ }
+//! [2] //! [3]
+
+ if (msWindowsFixedSizeDialogCheckBox->isChecked())
+ flags |= Qt::MSWindowsFixedSizeDialogHint;
+ if (x11BypassWindowManagerCheckBox->isChecked())
+ flags |= Qt::X11BypassWindowManagerHint;
+ if (framelessWindowCheckBox->isChecked())
+ flags |= Qt::FramelessWindowHint;
+ if (windowTitleCheckBox->isChecked())
+ flags |= Qt::WindowTitleHint;
+ if (windowSystemMenuCheckBox->isChecked())
+ flags |= Qt::WindowSystemMenuHint;
+ if (windowMinimizeButtonCheckBox->isChecked())
+ flags |= Qt::WindowMinimizeButtonHint;
+ if (windowMaximizeButtonCheckBox->isChecked())
+ flags |= Qt::WindowMaximizeButtonHint;
+ if (windowCloseButtonCheckBox->isChecked())
+ flags |= Qt::WindowCloseButtonHint;
+ if (windowContextHelpButtonCheckBox->isChecked())
+ flags |= Qt::WindowContextHelpButtonHint;
+ if (windowShadeButtonCheckBox->isChecked())
+ flags |= Qt::WindowShadeButtonHint;
+ if (windowStaysOnTopCheckBox->isChecked())
+ flags |= Qt::WindowStaysOnTopHint;
+ if (windowStaysOnBottomCheckBox->isChecked())
+ flags |= Qt::WindowStaysOnBottomHint;
+ if (customizeWindowHintCheckBox->isChecked())
+ flags |= Qt::CustomizeWindowHint;
+
+ previewWindow->setWindowFlags(flags);
+//! [3] //! [4]
+
+ QPoint pos = previewWindow->pos();
+ if (pos.x() < 0)
+ pos.setX(0);
+ if (pos.y() < 0)
+ pos.setY(0);
+ previewWindow->move(pos);
+ previewWindow->show();
+}
+//! [4]
+
+//! [5]
+void ControllerWindow::createTypeGroupBox()
+{
+ typeGroupBox = new QGroupBox(tr("Type"));
+
+ windowRadioButton = createRadioButton(tr("Window"));
+ dialogRadioButton = createRadioButton(tr("Dialog"));
+ sheetRadioButton = createRadioButton(tr("Sheet"));
+ drawerRadioButton = createRadioButton(tr("Drawer"));
+ popupRadioButton = createRadioButton(tr("Popup"));
+ toolRadioButton = createRadioButton(tr("Tool"));
+ toolTipRadioButton = createRadioButton(tr("Tooltip"));
+ splashScreenRadioButton = createRadioButton(tr("Splash screen"));
+ windowRadioButton->setChecked(true);
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(windowRadioButton, 0, 0);
+ layout->addWidget(dialogRadioButton, 1, 0);
+ layout->addWidget(sheetRadioButton, 2, 0);
+ layout->addWidget(drawerRadioButton, 3, 0);
+ layout->addWidget(popupRadioButton, 0, 1);
+ layout->addWidget(toolRadioButton, 1, 1);
+ layout->addWidget(toolTipRadioButton, 2, 1);
+ layout->addWidget(splashScreenRadioButton, 3, 1);
+ typeGroupBox->setLayout(layout);
+}
+//! [5]
+
+//! [6]
+void ControllerWindow::createHintsGroupBox()
+{
+ hintsGroupBox = new QGroupBox(tr("Hints"));
+
+ msWindowsFixedSizeDialogCheckBox =
+ createCheckBox(tr("MS Windows fixed size dialog"));
+ x11BypassWindowManagerCheckBox =
+ createCheckBox(tr("X11 bypass window manager"));
+ framelessWindowCheckBox = createCheckBox(tr("Frameless window"));
+ windowTitleCheckBox = createCheckBox(tr("Window title"));
+ windowSystemMenuCheckBox = createCheckBox(tr("Window system menu"));
+ windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button"));
+ windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button"));
+ windowCloseButtonCheckBox = createCheckBox(tr("Window close button"));
+ windowContextHelpButtonCheckBox =
+ createCheckBox(tr("Window context help button"));
+ windowShadeButtonCheckBox = createCheckBox(tr("Window shade button"));
+ windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top"));
+ windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom"));
+ customizeWindowHintCheckBox= createCheckBox(tr("Customize window"));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0);
+ layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0);
+ layout->addWidget(framelessWindowCheckBox, 2, 0);
+ layout->addWidget(windowTitleCheckBox, 3, 0);
+ layout->addWidget(windowSystemMenuCheckBox, 4, 0);
+ layout->addWidget(windowMinimizeButtonCheckBox, 0, 1);
+ layout->addWidget(windowMaximizeButtonCheckBox, 1, 1);
+ layout->addWidget(windowCloseButtonCheckBox, 2, 1);
+ layout->addWidget(windowContextHelpButtonCheckBox, 3, 1);
+ layout->addWidget(windowShadeButtonCheckBox, 4, 1);
+ layout->addWidget(windowStaysOnTopCheckBox, 5, 1);
+ layout->addWidget(windowStaysOnBottomCheckBox, 6, 1);
+ layout->addWidget(customizeWindowHintCheckBox, 5, 0);
+ hintsGroupBox->setLayout(layout);
+}
+//! [6]
+
+//! [7]
+QCheckBox *ControllerWindow::createCheckBox(const QString &text)
+{
+ QCheckBox *checkBox = new QCheckBox(text);
+ connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
+ return checkBox;
+}
+//! [7]
+
+//! [8]
+QRadioButton *ControllerWindow::createRadioButton(const QString &text)
+{
+ QRadioButton *button = new QRadioButton(text);
+ connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
+ return button;
+}
+//! [8]
diff --git a/examples/widgets/windowflags/controllerwindow.h b/examples/widgets/windowflags/controllerwindow.h
new file mode 100644
index 0000000000..caa76987b1
--- /dev/null
+++ b/examples/widgets/windowflags/controllerwindow.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CONTROLLERWINDOW_H
+#define CONTROLLERWINDOW_H
+
+#include <QWidget>
+
+#include "previewwindow.h"
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QGroupBox;
+class QLabel;
+class QPushButton;
+class QRadioButton;
+QT_END_NAMESPACE
+
+//! [0]
+class ControllerWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ControllerWindow();
+
+private slots:
+ void updatePreview();
+
+private:
+ void createTypeGroupBox();
+ void createHintsGroupBox();
+ QCheckBox *createCheckBox(const QString &text);
+ QRadioButton *createRadioButton(const QString &text);
+
+ PreviewWindow *previewWindow;
+
+ QGroupBox *typeGroupBox;
+ QGroupBox *hintsGroupBox;
+ QPushButton *quitButton;
+
+ QRadioButton *windowRadioButton;
+ QRadioButton *dialogRadioButton;
+ QRadioButton *sheetRadioButton;
+ QRadioButton *drawerRadioButton;
+ QRadioButton *popupRadioButton;
+ QRadioButton *toolRadioButton;
+ QRadioButton *toolTipRadioButton;
+ QRadioButton *splashScreenRadioButton;
+
+ QCheckBox *msWindowsFixedSizeDialogCheckBox;
+ QCheckBox *x11BypassWindowManagerCheckBox;
+ QCheckBox *framelessWindowCheckBox;
+ QCheckBox *windowTitleCheckBox;
+ QCheckBox *windowSystemMenuCheckBox;
+ QCheckBox *windowMinimizeButtonCheckBox;
+ QCheckBox *windowMaximizeButtonCheckBox;
+ QCheckBox *windowCloseButtonCheckBox;
+ QCheckBox *windowContextHelpButtonCheckBox;
+ QCheckBox *windowShadeButtonCheckBox;
+ QCheckBox *windowStaysOnTopCheckBox;
+ QCheckBox *windowStaysOnBottomCheckBox;
+ QCheckBox *customizeWindowHintCheckBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/windowflags/main.cpp b/examples/widgets/windowflags/main.cpp
new file mode 100644
index 0000000000..8dd71ed0a5
--- /dev/null
+++ b/examples/widgets/windowflags/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "controllerwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ ControllerWindow controller;
+ controller.show();
+ return app.exec();
+}
diff --git a/examples/widgets/windowflags/previewwindow.cpp b/examples/widgets/windowflags/previewwindow.cpp
new file mode 100644
index 0000000000..5847af1c63
--- /dev/null
+++ b/examples/widgets/windowflags/previewwindow.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "previewwindow.h"
+
+//! [0]
+PreviewWindow::PreviewWindow(QWidget *parent)
+ : QWidget(parent)
+{
+ textEdit = new QTextEdit;
+ textEdit->setReadOnly(true);
+ textEdit->setLineWrapMode(QTextEdit::NoWrap);
+
+ closeButton = new QPushButton(tr("&Close"));
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(textEdit);
+ layout->addWidget(closeButton);
+ setLayout(layout);
+
+ setWindowTitle(tr("Preview"));
+}
+//! [0]
+
+//! [1]
+void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
+{
+ QWidget::setWindowFlags(flags);
+
+ QString text;
+
+ Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
+ if (type == Qt::Window) {
+ text = "Qt::Window";
+ } else if (type == Qt::Dialog) {
+ text = "Qt::Dialog";
+ } else if (type == Qt::Sheet) {
+ text = "Qt::Sheet";
+ } else if (type == Qt::Drawer) {
+ text = "Qt::Drawer";
+ } else if (type == Qt::Popup) {
+ text = "Qt::Popup";
+ } else if (type == Qt::Tool) {
+ text = "Qt::Tool";
+ } else if (type == Qt::ToolTip) {
+ text = "Qt::ToolTip";
+ } else if (type == Qt::SplashScreen) {
+ text = "Qt::SplashScreen";
+ }
+
+ if (flags & Qt::MSWindowsFixedSizeDialogHint)
+ text += "\n| Qt::MSWindowsFixedSizeDialogHint";
+ if (flags & Qt::X11BypassWindowManagerHint)
+ text += "\n| Qt::X11BypassWindowManagerHint";
+ if (flags & Qt::FramelessWindowHint)
+ text += "\n| Qt::FramelessWindowHint";
+ if (flags & Qt::WindowTitleHint)
+ text += "\n| Qt::WindowTitleHint";
+ if (flags & Qt::WindowSystemMenuHint)
+ text += "\n| Qt::WindowSystemMenuHint";
+ if (flags & Qt::WindowMinimizeButtonHint)
+ text += "\n| Qt::WindowMinimizeButtonHint";
+ if (flags & Qt::WindowMaximizeButtonHint)
+ text += "\n| Qt::WindowMaximizeButtonHint";
+ if (flags & Qt::WindowCloseButtonHint)
+ text += "\n| Qt::WindowCloseButtonHint";
+ if (flags & Qt::WindowContextHelpButtonHint)
+ text += "\n| Qt::WindowContextHelpButtonHint";
+ if (flags & Qt::WindowShadeButtonHint)
+ text += "\n| Qt::WindowShadeButtonHint";
+ if (flags & Qt::WindowStaysOnTopHint)
+ text += "\n| Qt::WindowStaysOnTopHint";
+ if (flags & Qt::CustomizeWindowHint)
+ text += "\n| Qt::CustomizeWindowHint";
+
+ textEdit->setPlainText(text);
+}
+//! [1]
diff --git a/examples/widgets/windowflags/previewwindow.h b/examples/widgets/windowflags/previewwindow.h
new file mode 100644
index 0000000000..15c849aa48
--- /dev/null
+++ b/examples/widgets/windowflags/previewwindow.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PREVIEWWINDOW_H
+#define PREVIEWWINDOW_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class PreviewWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PreviewWindow(QWidget *parent = 0);
+
+ void setWindowFlags(Qt::WindowFlags flags);
+
+private:
+ QTextEdit *textEdit;
+ QPushButton *closeButton;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/windowflags/windowflags.pro b/examples/widgets/windowflags/windowflags.pro
new file mode 100644
index 0000000000..58985d8a66
--- /dev/null
+++ b/examples/widgets/windowflags/windowflags.pro
@@ -0,0 +1,13 @@
+HEADERS = controllerwindow.h \
+ previewwindow.h
+SOURCES = controllerwindow.cpp \
+ previewwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/windowflags
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS windowflags.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/widgets/windowflags
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/xml/README b/examples/xml/README
new file mode 100644
index 0000000000..a6d81bb58a
--- /dev/null
+++ b/examples/xml/README
@@ -0,0 +1,40 @@
+XML parsing and handling is supported through SAX and DOM compliant APIs.
+
+Qt's SAX compliant classes allow you to parse XML incrementally; the DOM
+classes enable more complex document-level operations to be performed on
+XML files.
+
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/xml/dombookmarks/dombookmarks.pro b/examples/xml/dombookmarks/dombookmarks.pro
new file mode 100644
index 0000000000..d071ccd0ee
--- /dev/null
+++ b/examples/xml/dombookmarks/dombookmarks.pro
@@ -0,0 +1,20 @@
+HEADERS = mainwindow.h \
+ xbeltree.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ xbeltree.cpp
+QT += xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/dombookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dombookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/dombookmarks
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
+wince*: {
+ addFiles.files = frank.xbel jennifer.xbel
+ addFiles.path = "\\My Documents"
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/xml/dombookmarks/frank.xbel b/examples/xml/dombookmarks/frank.xbel
new file mode 100644
index 0000000000..6bd63b8b07
--- /dev/null
+++ b/examples/xml/dombookmarks/frank.xbel
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="yes">
+ <title>Literate Programming</title>
+ <bookmark href="http://www.vivtek.com/litprog.html">
+ <title>Synopsis of Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html">
+ <title>Literate Programming: Propaganda and Tools</title>
+ </bookmark>
+ <bookmark href="http://www.isy.liu.se/%7Eturbell/litprog/">
+ <title>Literate Programming by Henrik Turbell</title>
+ </bookmark>
+ <bookmark href="http://www.desy.de/user/projects/LitProg.html">
+ <title>Literate Programming Library</title>
+ </bookmark>
+ <bookmark href="http://www.loria.fr/services/tex/english/litte.html">
+ <title>Literate Programming Basics</title>
+ </bookmark>
+ <bookmark href="http://ei.cs.vt.edu/%7Ecs5014/courseNotes/4.LiterateProgramming/literate_prog.html">
+ <title>Literate Programming Overview</title>
+ </bookmark>
+ <bookmark href="http://www.perl.com/pub/a/tchrist/litprog.html">
+ <title>POD is not Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://www.cornellcollege.edu/%7Eltabak/publications/articles/swsafety.html">
+ <title>Computers That We Can Count On</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/litpro/issues-and-problems.html">
+ <title>Literate Programming - Issues and Problems</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?LiterateProgramming">
+ <title>Literate Programming - Wiki Pages</title>
+ </bookmark>
+ <bookmark href="http://developers.slashdot.org/developers/02/05/19/2216233.shtml">
+ <title>What is well-commented code?</title>
+ </bookmark>
+ <bookmark href="http://liinwww.ira.uka.de/bibliography/SE/litprog.html">
+ <title>Bibliography on literate programming - A searchable bibliography</title>
+ </bookmark>
+ <bookmark href="http://www2.umassd.edu/SWPI/ProcessBibliography/bib-codereading.html">
+ <title>Program comprehension and code reading bibliography</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/elucidative-programming/">
+ <title>Elucidative Programming</title>
+ </bookmark>
+ <bookmark href="http://www.msu.edu/%7Epfaffben/avl/index.html">
+ <title>AVL Trees (TexiWeb)</title>
+ </bookmark>
+ <bookmark href="http://literate-programming.wikiverse.org/">
+ <title>Literate Programming on Wikiverse</title>
+ </bookmark>
+ <bookmark href="http://www.pbrt.org/">
+ <title>Physically Based Rendering: From Theory to Implementation</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Useful C++ Links</title>
+ <folder folded="no">
+ <title>STL</title>
+ <bookmark href="http://www.sgi.com/tech/stl/table_of_contents.html">
+ <title>STL Reference Documentation</title>
+ </bookmark>
+ <bookmark href="http://www.yrl.co.uk/~phil/stl/stl.htmlx">
+ <title>STL Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.cppreference.com/cpp_stl.html">
+ <title>STL Reference</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Qt</title>
+ <bookmark href="http://qt.nokia.com/doc/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>Qt Home Page</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>IOStreams</title>
+ <bookmark href="http://www.cplusplus.com/ref/iostream/index.html">
+ <title>IO Stream Library</title>
+ </bookmark>
+ <bookmark href="http://courses.cs.vt.edu/~cs2604/fall01/binio.html">
+ <title>Binary I/O</title>
+ </bookmark>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/input-output.html">
+ <title>I/O Stream FAQ</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>gdb</title>
+ <bookmark href="http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html">
+ <title>GDB Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.gnu.org/manual/gdb-4.17/html_mono/gdb.html">
+ <title>Debugging with GDB</title>
+ </bookmark>
+ <bookmark href="http://www.cs.washington.edu/orgs/acm/tutorials/dev-in-unix/gdb-refcard.pdf">
+ <title>GDB Quick Reference Page (PDF) (Handy)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Classes and Constructors</title>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/ctors.html">
+ <title>Constructor FAQ</title>
+ </bookmark>
+ <bookmark href="http://www.juicystudio.com/tutorial/cpp/index.html">
+ <title>Organizing Classes</title>
+ </bookmark>
+ </folder>
+ </folder>
+ <folder folded="yes">
+ <title>Software Documentation or System Documentation</title>
+ <bookmark href="http://www.martinfowler.com/distributedComputing/thud.html">
+ <title>The Almighty Thud</title>
+ </bookmark>
+ <bookmark href="http://msdn.microsoft.com/library/techart/cfr.htm">
+ <title>Microsoft Coding Techniques and Programming Practices</title>
+ </bookmark>
+ <bookmark href="http://www.bearcave.com/software/prog_docs.html">
+ <title>Software and Documentation</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?TheSourceCodeIsTheDesign">
+ <title>The Source Code is the Design</title>
+ </bookmark>
+ <bookmark href="http://www.bleading-edge.com/Publications/C++Journal/Cpjour2.htm">
+ <title>What is Software Design?</title>
+ </bookmark>
+ <bookmark href="http://www.mindprod.com/unmain.html">
+ <title>How To Write Unmaintainable Code</title>
+ </bookmark>
+ <bookmark href="http://www.idinews.com/selfDoc.html">
+ <title>Self Documenting Program Code Remains a Distant Goal</title>
+ </bookmark>
+ <bookmark href="http://www.sdmagazine.com/documents/s=730/sdm0106m/0106m.htm">
+ <title>Place Tab A in Slot B</title>
+ </bookmark>
+ <bookmark href="http://www.holub.com/class/uml/uml.html">
+ <title>UML Reference Card</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>TeX Resources</title>
+ <bookmark href="http://www.tug.org/">
+ <title>The TeX User's Group</title>
+ </bookmark>
+ <bookmark href="http://www.miktex.org/">
+ <title>MikTeX website</title>
+ </bookmark>
+ <bookmark href="http://cm.bell-labs.com/who/hobby/MetaPost.html">
+ <title>MetaPost website</title>
+ </bookmark>
+ <bookmark href="http://pauillac.inria.fr/%7Emaranget/hevea/">
+ <title>HEVEA is a quite complete and fast LATEX to HTML translator</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Portable Document Format (PDF)</title>
+ <bookmark href="http://www.adobe.com/">
+ <title>Adobe - The postscript and PDF standards</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html">
+ <title>Reference Manual Portable Document Format</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/acrosdk/main.html">
+ <title>Adobe Acrobat Software Development Kit</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Literature Sites</title>
+ <bookmark href="http://www.cc.columbia.edu/cu/libraries/subjects/speccol.html">
+ <title>Guide to Special Collections (Columbia University)</title>
+ </bookmark>
+ <bookmark href="http://www.ipl.org/ref/litcrit/">
+ <title>Literary Criticism on the Web from the Internet Public Library</title>
+ </bookmark>
+ <bookmark href="http://www.victorianweb.org/">
+ <title>Victorian Web.</title>
+ </bookmark>
+ <bookmark href="http://vos.ucsb.edu/">
+ <title>Voice of the Shuttle.</title>
+ </bookmark>
+ <bookmark href="http://www.modjourn.brown.edu/">
+ <title>Modernist Journals Project</title>
+ </bookmark>
+ <bookmark href="http://www.poetspath.com">
+ <title>Museum of American Poetics</title>
+ </bookmark>
+ <bookmark href="http://www.english.uiuc.edu/maps/">
+ <title>Modern American Poetry</title>
+ </bookmark>
+ <bookmark href="http://www.findarticles.com/">
+ <title>FindArticles.com</title>
+ </bookmark>
+ <bookmark href="http://www.literaryhistory.com">
+ <title>Literary History</title>
+ </bookmark>
+ <bookmark href="http://www.litencyc.com/LitEncycFrame.htm">
+ <title>Literary Encyclopedia</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://texts.cdlib.org/ucpress/">
+ <title>The University of California Press</title>
+ </bookmark>
+ <bookmark href="http://www.letrs.indiana.edu/web/w/wright2/">
+ <title>Wright American Fiction, 1851-1875</title>
+ </bookmark>
+ <bookmark href="http://docsouth.unc.edu/">
+ <title>Documenting the American South: Beginnings to 1920</title>
+ </bookmark>
+ <bookmark href="http://etext.lib.virginia.edu/eng-on.html">
+ <title>Electronic Text Center at the University of Virginia</title>
+ </bookmark>
+ <bookmark href="http://digital.nypl.org/schomburg/writers_aa19/">
+ <title>The Schomburg Center for Research in Black Culture</title>
+ </bookmark>
+ <bookmark href="http://www.infomotions.com/alex2/">
+ <title>Alex Catalogue of Electronic Texts.</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/dombookmarks/jennifer.xbel b/examples/xml/dombookmarks/jennifer.xbel
new file mode 100644
index 0000000000..36256fda0a
--- /dev/null
+++ b/examples/xml/dombookmarks/jennifer.xbel
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="no">
+ <title>Qt Resources</title>
+ <folder folded="yes">
+ <title>Qt Partners</title>
+ <bookmark href="http://partners.trolltech.com/partners/training.html">
+ <title>Training Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/service.html">
+ <title>Consultants and System Integrators</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/tech.html">
+ <title>Technology Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/resellers.html">
+ <title>Value Added Resellers (VARs)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Community Resources</title>
+ <bookmark href="http://www.qtforum.org/">
+ <title>QtForum.org</title>
+ </bookmark>
+ <bookmark href="http://www.digitalfanatics.org/projects/qt_tutorial/">
+ <title>The Independent Qt Tutorial</title>
+ </bookmark>
+ <bookmark href="http://prog.qt.free.fr/">
+ <title>French PROG.Qt</title>
+ </bookmark>
+ <bookmark href="http://www.qtforum.de/">
+ <title>German Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://www.korone.net/">
+ <title>Korean Qt Community Site</title>
+ </bookmark>
+ <bookmark href="http://prog.org.ru/forum/forum_14.html">
+ <title>Russian Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://qt4.digitalfanatics.org/">
+ <title>Digitalfanatics: The QT 4 Resource Center</title>
+ </bookmark>
+ <bookmark href="http://www.qtquestions.org/">
+ <title>QtQuestions</title>
+ </bookmark>
+ </folder>
+ <bookmark href="http://qt.nokia.com/doc/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>Qt home page</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/developer/faqs/">
+ <title>Frequently Asked Questions</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Online Dictionaries</title>
+ <bookmark href="http://www.dictionary.com/">
+ <title>Dictionary.com</title>
+ </bookmark>
+ <bookmark href="http://www.m-w.com/">
+ <title>Merriam-Webster Online</title>
+ </bookmark>
+ <bookmark href="http://dictionary.cambridge.org/">
+ <title>Cambridge Dictionaries Online</title>
+ </bookmark>
+ <bookmark href="http://www.onelook.com/">
+ <title>OneLook Dictionary Search</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="www.iee.et.tu-dresden.de/">
+ <title>The New English-German Dictionary</title>
+ </bookmark>
+ <bookmark href="http://dict.tu-chemnitz.de/">
+ <title>TU Chemnitz German-English Dictionary</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://atilf.atilf.fr/tlf.htm">
+ <title>Trésor de la Langue Française informatisé</title>
+ </bookmark>
+ <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/">
+ <title>Dictionnaire de l'Académie Française</title>
+ </bookmark>
+ <bookmark href="http://elsap1.unicaen.fr/cgi-bin/cherches.cgi">
+ <title>Dictionnaire des synonymes</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/dombookmarks/main.cpp b/examples/xml/dombookmarks/main.cpp
new file mode 100644
index 0000000000..71ce6aec0b
--- /dev/null
+++ b/examples/xml/dombookmarks/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ mainWin.open();
+ return app.exec();
+}
diff --git a/examples/xml/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp
new file mode 100644
index 0000000000..b3bfe64e17
--- /dev/null
+++ b/examples/xml/dombookmarks/mainwindow.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "xbeltree.h"
+
+MainWindow::MainWindow()
+{
+ xbelTree = new XbelTree;
+ setCentralWidget(xbelTree);
+
+ createActions();
+ createMenus();
+
+ statusBar()->showMessage(tr("Ready"));
+
+ setWindowTitle(tr("DOM Bookmarks"));
+ resize(480, 320);
+}
+
+void MainWindow::open()
+{
+ QString fileName =
+ QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SAX Bookmarks"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ if (xbelTree->read(&file))
+ statusBar()->showMessage(tr("File loaded"), 2000);
+}
+
+void MainWindow::saveAs()
+{
+ QString fileName =
+ QFileDialog::getSaveFileName(this, tr("Save Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SAX Bookmarks"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ if (xbelTree->write(&file))
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About DOM Bookmarks"),
+ tr("The <b>DOM Bookmarks</b> example demonstrates how to "
+ "use Qt's DOM classes to read and write XML "
+ "documents."));
+}
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addAction(exitAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
diff --git a/examples/xml/dombookmarks/mainwindow.h b/examples/xml/dombookmarks/mainwindow.h
new file mode 100644
index 0000000000..058f5cc221
--- /dev/null
+++ b/examples/xml/dombookmarks/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+class XbelTree;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void open();
+ void saveAs();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+
+ XbelTree *xbelTree;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *openAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/xml/dombookmarks/xbeltree.cpp b/examples/xml/dombookmarks/xbeltree.cpp
new file mode 100644
index 0000000000..2a072b2d54
--- /dev/null
+++ b/examples/xml/dombookmarks/xbeltree.cpp
@@ -0,0 +1,186 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbeltree.h"
+
+XbelTree::XbelTree(QWidget *parent)
+ : QTreeWidget(parent)
+{
+ QStringList labels;
+ labels << tr("Title") << tr("Location");
+
+ header()->setResizeMode(QHeaderView::Stretch);
+ setHeaderLabels(labels);
+
+ folderIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ folderIcon.addPixmap(style()->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ bookmarkIcon.addPixmap(style()->standardPixmap(QStyle::SP_FileIcon));
+}
+
+bool XbelTree::read(QIODevice *device)
+{
+ QString errorStr;
+ int errorLine;
+ int errorColumn;
+
+ if (!domDocument.setContent(device, true, &errorStr, &errorLine,
+ &errorColumn)) {
+ QMessageBox::information(window(), tr("DOM Bookmarks"),
+ tr("Parse error at line %1, column %2:\n%3")
+ .arg(errorLine)
+ .arg(errorColumn)
+ .arg(errorStr));
+ return false;
+ }
+
+ QDomElement root = domDocument.documentElement();
+ if (root.tagName() != "xbel") {
+ QMessageBox::information(window(), tr("DOM Bookmarks"),
+ tr("The file is not an XBEL file."));
+ return false;
+ } else if (root.hasAttribute("version")
+ && root.attribute("version") != "1.0") {
+ QMessageBox::information(window(), tr("DOM Bookmarks"),
+ tr("The file is not an XBEL version 1.0 "
+ "file."));
+ return false;
+ }
+
+ clear();
+
+ disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateDomElement(QTreeWidgetItem*,int)));
+
+ QDomElement child = root.firstChildElement("folder");
+ while (!child.isNull()) {
+ parseFolderElement(child);
+ child = child.nextSiblingElement("folder");
+ }
+
+ connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
+ this, SLOT(updateDomElement(QTreeWidgetItem*,int)));
+
+ return true;
+}
+
+bool XbelTree::write(QIODevice *device)
+{
+ const int IndentSize = 4;
+
+ QTextStream out(device);
+ domDocument.save(out, IndentSize);
+ return true;
+}
+
+void XbelTree::updateDomElement(QTreeWidgetItem *item, int column)
+{
+ QDomElement element = domElementForItem.value(item);
+ if (!element.isNull()) {
+ if (column == 0) {
+ QDomElement oldTitleElement = element.firstChildElement("title");
+ QDomElement newTitleElement = domDocument.createElement("title");
+
+ QDomText newTitleText = domDocument.createTextNode(item->text(0));
+ newTitleElement.appendChild(newTitleText);
+
+ element.replaceChild(newTitleElement, oldTitleElement);
+ } else {
+ if (element.tagName() == "bookmark")
+ element.setAttribute("href", item->text(1));
+ }
+ }
+}
+
+void XbelTree::parseFolderElement(const QDomElement &element,
+ QTreeWidgetItem *parentItem)
+{
+ QTreeWidgetItem *item = createItem(element, parentItem);
+
+ QString title = element.firstChildElement("title").text();
+ if (title.isEmpty())
+ title = QObject::tr("Folder");
+
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ item->setIcon(0, folderIcon);
+ item->setText(0, title);
+
+ bool folded = (element.attribute("folded") != "no");
+ setItemExpanded(item, !folded);
+
+ QDomElement child = element.firstChildElement();
+ while (!child.isNull()) {
+ if (child.tagName() == "folder") {
+ parseFolderElement(child, item);
+ } else if (child.tagName() == "bookmark") {
+ QTreeWidgetItem *childItem = createItem(child, item);
+
+ QString title = child.firstChildElement("title").text();
+ if (title.isEmpty())
+ title = QObject::tr("Folder");
+
+ childItem->setFlags(item->flags() | Qt::ItemIsEditable);
+ childItem->setIcon(0, bookmarkIcon);
+ childItem->setText(0, title);
+ childItem->setText(1, child.attribute("href"));
+ } else if (child.tagName() == "separator") {
+ QTreeWidgetItem *childItem = createItem(child, item);
+ childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
+ childItem->setText(0, QString(30, 0xB7));
+ }
+ child = child.nextSiblingElement();
+ }
+}
+
+QTreeWidgetItem *XbelTree::createItem(const QDomElement &element,
+ QTreeWidgetItem *parentItem)
+{
+ QTreeWidgetItem *item;
+ if (parentItem) {
+ item = new QTreeWidgetItem(parentItem);
+ } else {
+ item = new QTreeWidgetItem(this);
+ }
+ domElementForItem.insert(item, element);
+ return item;
+}
diff --git a/examples/xml/dombookmarks/xbeltree.h b/examples/xml/dombookmarks/xbeltree.h
new file mode 100644
index 0000000000..ad30de520c
--- /dev/null
+++ b/examples/xml/dombookmarks/xbeltree.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELTREE_H
+#define XBELTREE_H
+
+#include <QDomDocument>
+#include <QHash>
+#include <QIcon>
+#include <QTreeWidget>
+
+class XbelTree : public QTreeWidget
+{
+ Q_OBJECT
+
+public:
+ XbelTree(QWidget *parent = 0);
+
+ bool read(QIODevice *device);
+ bool write(QIODevice *device);
+
+private slots:
+ void updateDomElement(QTreeWidgetItem *item, int column);
+
+private:
+ void parseFolderElement(const QDomElement &element,
+ QTreeWidgetItem *parentItem = 0);
+ QTreeWidgetItem *createItem(const QDomElement &element,
+ QTreeWidgetItem *parentItem = 0);
+
+ QDomDocument domDocument;
+ QHash<QTreeWidgetItem *, QDomElement> domElementForItem;
+ QIcon folderIcon;
+ QIcon bookmarkIcon;
+};
+
+#endif
diff --git a/examples/xml/htmlinfo/apache_org.html b/examples/xml/htmlinfo/apache_org.html
new file mode 100644
index 0000000000..9e5e4d3a68
--- /dev/null
+++ b/examples/xml/htmlinfo/apache_org.html
@@ -0,0 +1,281 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <!--
+ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ This file is generated from XML source: DO NOT EDIT!
+ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ -->
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <link rel="stylesheet" href="./style/compressed.css" type="text/css" media="screen, projection"/>
+ <link rel="stylesheet" href="./style/style.css" type="text/css" media="screen, projection"/>
+ <!--[if IE]><link rel="stylesheet" href="./style/ie.css" type="text/css" media="screen, projection"/><![endif]-->
+<link rel="alternate" title="announce@apache.org Archives" type="application/atom+xml" href="http://mail-archives.apache.org/mod_mbox/www-announce/?format=atom" />
+ <meta name="author" content="The Apache Software Foundation" /><meta name="email" content="apache.AT.apache.DOT.org" />
+ <title>Welcome! - The Apache Software Foundation</title>
+ </head>
+ <body>
+ <div class="navigation">
+ <ul>
+ <li><a href="./foundation" title="About the Foundation">Foundation</a></li>
+ <li><a href="http://projects.apache.org" title="Apache Projects">Projects</a></li>
+ <li><a href="http://people.apache.org" title="Apache People">People</a></li>
+ <li><a href="./foundation/getinvolved.html" title="Get involved in Apache">Get Involved</a></li>
+ <li><a href="./foundation/sponsorship.html" title="Support the mission of Apache">Support Apache</a></li>
+ <li class="dlink"><a href="./dyn/closer.cgi" title="Download Apache projects">Download</a></li>
+ </ul>
+ </div>
+ <div class="container">
+ <hr class="space col"/>
+ <div class="block">
+ <div class="column span-24">
+ <div id="header">
+ <h1>The Apache Software Foundation<br />
+ <span class="alt"><small>Meritocracy in Action.</small></span></h1><p class="blurb">The Apache Software Foundation provides support for the Apache community of open-source software projects. The <a href="http://projects.apache.org/">Apache projects</a> are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field.</p><p class="highlight">We consider ourselves not simply a group of projects sharing a server, but rather a <em>community of developers and users</em>.</p>
+ </div>
+ </div>
+ </div>
+ <hr/>
+ <div class="block">
+ <div class="column span-15 first append-1">
+ <h3>
+ Latest News
+ </h3>
+ </div>
+ <div class="column span-8 las search">
+ <form action="http://www.google.com/search" method="get">
+ <input value="*.apache.org" name="sitesearch" type="hidden"/>
+ <input size="10" name="q" id="query" type="text"/>
+ <input name="Search" value="Go" type="submit"/>
+ </form>
+ </div>
+ </div>
+ <div class="block content">
+ <div class="column span-15 colborder">
+
+<div class="section-content">
+<p><em>If you would like to keep up with news and announcements from the
+foundation and all its projects, you can subscribe to the
+<a href="foundation/mailinglists.html#foundation-announce">Apache
+Announcements List</a></em>.</p>
+
+<h4 id="apachecon-eu">
+ Free Video Streams from ApacheCon Europe 2008
+</h4>
+<div class="section-content">
+<a href="http://www.eu.apachecon.com/"><img src="images/eu_2008_logo.jpg" alt="ApacheCon Europe 2008" title="ApacheCon Europe 2008" border="0" align="right" /></a>
+<p>
+ApacheCon Europe 2008 held in Amsterdam was a great success, and attracted higher
+than ever attendance figures, with about 500 registered attendees. This
+figure represents an increase of more than 40% over the previous year,
+demonstrating the rapidly growing interest in Apache and Open Source software
+amongst European businesses.
+
+If you have not been able to attend ApacheCon Europe, you can still watch
+<a href="http://streaming.linux-magazin.de/en/archive_apachecon08eu.htm">videos of all keynotes and select talks online</a>. Keynote sessions
+and the opening plenary are available <b>free of charge</b>:</p>
+<ul>
+<li><a href="http://streaming.linux-magazin.de/events/apacheconfree/archive/jjagielski/frames-java.htm" onclick="window.open(this.href, '_blank', 'width=1024, height=768'); return false;">State of the Feather</a>
+ by Jim Jagielski, Chairman of the Apache Software Foundation</li>
+<li><a href="http://streaming.linux-magazin.de/events/apacheconfree/archive/cschmidt/frames-java.htm" onclick="window.open(this.href, '_blank', 'width=1024, height=768'); return false;">Using Audio Technology and Open Content to Reduce Global Illiteracy, Poverty and Disease</a>
+ by Cliff Schmidt, Executive Director of Literacy Bridge</li>
+<li><a href="http://streaming.linux-magazin.de/events/apacheconfree/archive/rghosh/frames-java.htm" onclick="window.open(this.href, '_blank', 'width=1024, height=768'); return false;">Apache and Steam Engines: the Magic of Collaborative Innovation</a>
+ by Rishab Aiyer Ghosh, Open Source Initiative Board Member</li>
+<li><a href="http://streaming.linux-magazin.de/events/apacheconfree/archive/rfielding/frames-java.htm" onclick="window.open(this.href, '_blank', 'width=1024, height=768'); return false;">Apache 3.0 (a Tall Tale)</a>
+ by Roy Fielding, Co-founder of The Apache Software Foundation,
+ and Vice President, Apache HTTP Server</li>
+</ul>
+<p>The talks of the following select ApacheCon Europe tracks are
+available for just 49 Euro:
+<a href="http://streaming.linux-magazin.de/en/archive_apachecon08eu.htm#wednesday">System Administration</a>,
+<a href="http://streaming.linux-magazin.de/en/archive_apachecon08eu.htm#thursday">Web Security</a>,
+<a href="http://streaming.linux-magazin.de/en/archive_apachecon08eu.htm#friday">Web Services and Web 2.0</a>.
+</p>
+<hr />
+</div>
+
+<h4 id="apachecon-us">
+ ApacheCon US 2008 in New Orleans!
+</h4>
+<div class="section-content">
+<p>
+ ApacheCon US 2008 will be held 3 November through 7 November in
+ New Orleans, Louisiana.
+ The Call for Papers has already closed and the program and further
+ information will be made available soon on the ApacheCon US 2008
+ Web site <a href="http://www.us.apachecon.com/us2008/"><strong>www.us.apachecon.com</strong></a>.
+ If you would like to receive information about ApacheCon US 2008, please
+ <a href="mailto:announce-subscribe@apachecon.com">subscribe to
+ the ApacheCon announcement mailing list</a>.
+ </p>
+<hr />
+</div>
+
+<h4 id="sun_jck_letter">
+ Notice regarding open letter to Sun Microsystems
+</h4>
+<div class="section-content">
+<p>
+ The Apache Software Foundation has written an <a href="jcp/sunopenletter.html">open letter</a>
+ to Sun Microsystems regarding our inabillity to acquire an acceptable license for the test kit
+ for Java SE needed by <a href="http://harmony.apache.org">Apache Harmony</a>. For futher information
+ please see the <a href="jcp/sunopenletterfaq.html">FAQ</a> and direct all questions to Apache's VP
+ for JCP issues, geirm at apache dot org, or our regular press inquiry address, press at apache dot org.
+ </p>
+</div>
+</div>
+ </div>
+ <div class="column span-8 last">
+ <div class="block">
+ <div class="nav column span-11">
+ <div>
+ <div class="menuheader"><a
+href="http://projects.apache.org/">Apache Projects</a></div>
+ <ul>
+ <li><a href="http://httpd.apache.org/" title="Apache Web Server (httpd)">HTTP Server</a></li>
+ <li><a href="http://activemq.apache.org/" title="Distributed Messaging System">ActiveMQ</a></li>
+ <li><a href="http://ant.apache.org/" title="Java-based build tool">Ant</a></li>
+ <li><a href="http://apr.apache.org/" title="Apache Portable Runtime libraries">APR</a></li>
+ <li><a href="http://archiva.apache.org/" title="Build Artifact Repository Manager">Archiva</a></li>
+ <li><a href="http://beehive.apache.org/" title="Metadata frameworks for enterprise applications">Beehive</a></li>
+ <li><a href="http://cayenne.apache.org/" title="User-friendly Java ORM with Tools">Cayenne</a></li>
+ <li><a href="http://cocoon.apache.org/" title="Web development framework: separation of concerns, component-based">Cocoon</a></li>
+ <li><a href="http://commons.apache.org/" title="Reusable Java components">Commons</a></li>
+ <li><a href="http://continuum.apache.org/" title="Continuous Integration and Build Server">Continuum</a></li>
+ <li><a href="http://cxf.apache.org/" title="Service Framework">CXF</a></li>
+ <li><a href="http://db.apache.org/" title="Database access">DB</a></li>
+ <li><a href="http://directory.apache.org/" title="Apache Directory Server">Directory</a></li>
+ <li><a href="http://excalibur.apache.org/" title="Embeddable software libraries related to component and service management access">Excalibur</a></li>
+ <li><a href="http://felix.apache.org/" title="OSGi Framework and components.">Felix</a></li>
+ <li><a href="http://forrest.apache.org/" title="Aggregated multi-channel documentation, separation of concerns">Forrest</a></li>
+ <li><a href="http://geronimo.apache.org/" title="Java2, Enterprise Edition (J2EE) container">Geronimo</a></li>
+ <li><a href="http://gump.apache.org/" title="Continuous integration of open source projects">Gump</a></li>
+ <li><a href="http://hadoop.apache.org/" title="Distributed computing platform">Hadoop</a></li>
+ <li><a href="http://harmony.apache.org/" title="Open source implementation of Java SE">Harmony</a></li>
+ <li><a href="http://hivemind.apache.org/" title="A services and configuration microkernel">HiveMind</a></li>
+ <li><a href="http://hc.apache.org/" title="Java toolset of low level HTTP components">HttpComponents</a></li>
+ <li><a href="http://ibatis.apache.org/" title="SQL Data Mapper for Java and .NET">iBATIS</a></li>
+ <li><a href="http://incubator.apache.org/" title="Shepherd for new projects">Incubator</a></li>
+ <li><a href="http://jackrabbit.apache.org/" title="Content Repository for Java">Jackrabbit</a></li>
+ <li><a href="http://jakarta.apache.org/" title="Server-side Java">Jakarta</a></li>
+ <li><a href="http://james.apache.org/" title="Java Apache Mail Enterprise Server">James</a></li>
+ <li><a href="http://labs.apache.org/" title="The Innovation Laboratories of the Apache Software Foundation">Labs</a></li>
+ <li><a href="http://lenya.apache.org/" title="Content Management System">Lenya</a></li>
+ <li><a href="http://logging.apache.org/" title="Cross-language logging services">Logging</a></li>
+ <li><a href="http://lucene.apache.org/" title="Search engine library">Lucene</a></li>
+ <li><a href="http://maven.apache.org/" title="Java project management and comprehension tools">Maven</a></li>
+ <li><a href="http://mina.apache.org/" title="Multipurpose Infrastructure for Network Application">Mina</a></li>
+ <li><a href="http://myfaces.apache.org/" title="JavaServer(tm) Faces implementation and components">MyFaces</a></li>
+ <li><a href="http://ode.apache.org/" title="Orchestration Director Engine: Business Process Management (BPM), Process Orchestration and Workflow through service compositioni.">ODE</a></li>
+ <li><a href="http://ofbiz.apache.org/" title="Open for Business: enterprise automation software">OFBiz</a></li>
+ <li><a href="http://openejb.apache.org/" title="OpenEJB: a modular, configurable, and extendable EJB Container System and Server">OpenEJB</a></li>
+ <li><a href="http://openjpa.apache.org/" title="OpenJPA: Object Relational Mapping for Java">OpenJPA</a></li>
+ <li><a href="http://perl.apache.org/" title="Dynamic websites using Perl">Perl</a></li>
+ <li><a href="http://poi.apache.org/" title="Java API for OLE 2 Compound Documents">POI</a></li>
+ <li><a href="http://portals.apache.org/" title="Portal technology">Portals</a></li>
+ <li><a href="http://roller.apache.org/" title="Java blog server">Roller</a></li>
+ <li><a href="http://santuario.apache.org/" title="XML Security in Java and C++">Santuario</a></li>
+ <li><a href="http://servicemix.apache.org/" title="Enterprise Service Bus">ServiceMix</a></li>
+ <li><a href="http://shale.apache.org/" title="Web application framework based on JavaServer(tm) Faces">Shale</a></li>
+ <li><a href="http://spamassassin.apache.org/" title="Mail filter to identify spam">SpamAssassin</a></li>
+ <li><a href="http://stdcxx.apache.org/" title="Apache C++ Standard Library">STDCXX</a></li>
+ <li><a href="http://struts.apache.org/" title="Model 2 framework for building Java web applications">Struts</a></li>
+ <li><a href="http://synapse.apache.org/" title="Enterprise Service Bus and Mediation Framework">Synapse</a></li>
+ <li><a href="http://tapestry.apache.org/" title="Component-based Java Web Application Framework">Tapestry</a></li>
+ <li><a href="http://tcl.apache.org/" title="Dynamic websites using TCL">TCL</a></li>
+ <li><a href="http://tiles.apache.org/" title="A templating framework for web application user interfaces">Tiles</a></li>
+ <li><a href="http://tomcat.apache.org/" title="A Java Servlet and JSP Container">Tomcat</a></li>
+ <li><a href="http://turbine.apache.org/" title="A Java Servlet Web Application Framework and associated component library">
+ Turbine</a></li>
+ <li><a href="http://velocity.apache.org/" title="A Java Templating Engine">Velocity</a></li>
+ <li><a href="http://wicket.apache.org/" title="Component-based Java Web Application Framework.">Wicket</a></li>
+ <li><a href="http://ws.apache.org/">Web Services</a></li>
+ <li><a href="http://xalan.apache.org/" title="XSLT processors in Java and C++">Xalan</a></li>
+ <li><a href="http://xerces.apache.org/" title="XML parsers in Java, C++ and Perl">Xerces</a></li>
+ <li><a href="http://xml.apache.org/" title="XML solutions focused on the web">XML</a></li>
+ <li><a href="http://xmlbeans.apache.org/" title="XML-Java binding tool">XMLBeans</a></li>
+ <li><a href="http://xmlgraphics.apache.org/" title="Conversion from XML to graphical output">XML Graphics</a></li>
+ </ul>
+ </div>
+ </div>
+ <div class="nav column prepend-1 span-12 last">
+ <h6><a
+href="/foundation/">Foundation</a></h6>
+ <ul>
+ <li><a href="/foundation/faq.html">FAQ</a></li>
+ <li><a href="/licenses/">Licenses</a></li>
+ <li><a href="/foundation/news.html">News</a></li>
+ <li><a href="/foundation/records/">Public Records</a></li>
+ <li><a href="/foundation/sponsorship.html">Sponsorship</a></li>
+ <li><a href="/foundation/contributing.html">Donations</a></li>
+ <li><a href="/foundation/thanks.html">Thanks</a></li>
+ <li><a href="/foundation/contact.html">Contact</a></li>
+ </ul>
+ <h6>Foundation Projects</h6>
+ <ul>
+ <li><a href="/foundation/conferences.html" title="Meetings of developers and users">Conferences</a></li>
+ <li><a href="/dev/" title="ASF Infrastructure: Operations and howto documents for PMCs and contributors">Infrastructure</a></li>
+ <li><a href="/jcp/" title="Apache and the Java Community Process">JCP</a></li>
+ </ul>
+ <h6>How it works</h6>
+ <ul>
+ <li><a href="/foundation/how-it-works.html">Introduction</a></li>
+ <li><a href="/foundation/how-it-works.html#meritocracy">Meritocracy</a></li>
+ <li><a href="/foundation/how-it-works.html#structure">Structure</a></li>
+ <li><a href="/foundation/how-it-works.html#roles">Roles</a></li>
+ <li><a href="/foundation/how-it-works.html#management">Collaboration</a></li>
+ <li><a href="/foundation/how-it-works.html#infrastructure">Infrastructure</a></li>
+ <li><a href="/foundation/how-it-works.html#incubator">Incubator</a></li>
+ <li><a href="/foundation/how-it-works.html#other">Other entities</a></li>
+ <li><a href="/foundation/glossary.html">Glossary</a></li>
+ <li><a href="/foundation/voting.html">Voting</a></li>
+ </ul>
+ <h6><a
+href="/foundation/getinvolved.html">Get Involved</a></h6>
+ <ul>
+ <li><a href="/foundation/mailinglists.html">Mailing Lists</a></li>
+ <li><a href="/dev/version-control.html">Version Control</a></li>
+ <li><a href="/dev/">Developer Info</a></li>
+ </ul>
+ <h6>Download</h6>
+ <ul>
+ <li><a href="/dyn/closer.cgi">from a mirror</a></li>
+ </ul>
+ <h6>Related Sites</h6>
+ <ul>
+ <li><a href="http://apachecon.com/" title="Official Apache Conference">ApacheCon</a></li>
+ <li><a href="http://apachebookstore.com/" title="Apache Books">Bookstore</a></li>
+ <li><a href="http://feathercast.org/" title="Apache Podcasts">Feathercast</a></li>
+ <li><a href="http://planetapache.org/" title="Apache Community Blogs">PlanetApache</a></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="column span-24 footer">
+ <hr/>
+ <p>Copyright &#169; 2008 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
+
diff --git a/examples/xml/htmlinfo/htmlinfo.pro b/examples/xml/htmlinfo/htmlinfo.pro
new file mode 100644
index 0000000000..ca64b346a7
--- /dev/null
+++ b/examples/xml/htmlinfo/htmlinfo.pro
@@ -0,0 +1,19 @@
+SOURCES += main.cpp
+QT -= gui
+
+wince*|symbian:{
+ htmlfiles.files = *.html
+ htmlfiles.path = .
+ DEPLOYMENT += htmlfiles
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/htmlinfo
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.html htmlinfo.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/htmlinfo
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C609
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp
new file mode 100644
index 0000000000..cb7ac528f0
--- /dev/null
+++ b/examples/xml/htmlinfo/main.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore>
+
+void parseHtmlFile(QTextStream &out, const QString &fileName) {
+ QFile file(fileName);
+
+ out << "Analysis of HTML file: " << fileName << endl;
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ out << " Couldn't open the file." << endl << endl << endl;
+ return;
+ }
+
+//! [0]
+ QXmlStreamReader reader(&file);
+//! [0]
+
+//! [1]
+ int paragraphCount = 0;
+ QStringList links;
+ QString title;
+ while (!reader.atEnd()) {
+ reader.readNext();
+ if (reader.isStartElement()) {
+ if (reader.name() == "title")
+ title = reader.readElementText();
+ else if(reader.name() == "a")
+ links.append(reader.attributes().value("href").toString());
+ else if(reader.name() == "p")
+ ++paragraphCount;
+ }
+ }
+//! [1]
+
+//! [2]
+ if (reader.hasError()) {
+ out << " The HTML file isn't well-formed: " << reader.errorString()
+ << endl << endl << endl;
+ return;
+ }
+//! [2]
+
+ out << " Title: \"" << title << "\"" << endl
+ << " Number of paragraphs: " << paragraphCount << endl
+ << " Number of links: " << links.size() << endl
+ << " Showing first few links:" << endl;
+
+ while(links.size() > 5)
+ links.removeLast();
+
+ foreach(QString link, links)
+ out << " " << link << endl;
+ out << endl << endl;
+}
+
+int main(int argc, char **argv)
+{
+ // initialize QtCore application
+ QCoreApplication app(argc, argv);
+
+ // get a list of all html files in the current directory
+ QStringList filter;
+ filter << "*.htm";
+ filter << "*.html";
+ QStringList htmlFiles = QDir::current().entryList(filter, QDir::Files);
+
+ QTextStream out(stdout);
+
+ if (htmlFiles.isEmpty()) {
+ out << "No html files available.";
+ return 1;
+ }
+
+ // parse each html file and write the result to file/stream
+ foreach(QString file, htmlFiles)
+ parseHtmlFile(out, file);
+
+ return 0;
+}
diff --git a/examples/xml/htmlinfo/nokia_com.html b/examples/xml/htmlinfo/nokia_com.html
new file mode 100644
index 0000000000..46d4c95ee6
--- /dev/null
+++ b/examples/xml/htmlinfo/nokia_com.html
@@ -0,0 +1,215 @@
+
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+
+
+ <!--startindex-->
+ <title>Nokia - Nokia on the Web</title>
+
+
+ <meta name="description" content="Nokia is the world's leading mobile phone supplier and a leading supplier of mobile and fixed telecom networks including related customer services."/>
+ <meta name="keywords" content="Nokia,mobile phones,cellular,telecommunications,wireless networks,datacom,GSM,multimedia terminals,handsets,customer services,press releases,financial information,student exchange,open positions,employment opportunities,career opportunities"/>
+ <meta name="modified" content=""/>
+ <meta name="category" content="Landing Page Global Flash"/>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="siteid" content="101"/>
+
+ <!--stopindex-->
+ <link href="/css/style_46.css" rel="stylesheet" type="text/css">
+
+ <link href="/NOKIA_COM_1/Home/Landing_page_2007/wayfinder.css" rel="stylesheet" type="text/css"/>
+
+<script type="text/javascript">
+ var useHbx = true;
+</script>
+
+
+<!--WEBSIDESTORY CODE HBX1.0 (Universal)-->
+<!--COPYRIGHT 1997-2005 WEBSIDESTORY,INC. ALL RIGHTS RESERVED. U.S.PATENT No. 6,393,479B1. MORE INFO:http://websidestory.com/privacy-->
+<script language="javascript">
+var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
+var hbx=_hbEvent("pv");hbx.vpc="HBX0100u";hbx.gn="ehg-nokiafin.hitbox.com";
+
+//BEGIN EDITABLE SECTION
+//CONFIGURATION VARIABLES
+hbx.acct="DM550514HPNZ";//ACCOUNT NUMBER(S)
+hbx.pn="Home";//PAGE NAME(S)
+hbx.mlc="/Home";//MULTI-LEVEL CONTENT CATEGORY
+hbx.pndef="title";//DEFAULT PAGE NAME
+hbx.ctdef="full";//DEFAULT CONTENT CATEGORY
+
+//OPTIONAL PAGE VARIABLES
+//ACTION SETTINGS
+hbx.fv="";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME
+hbx.lt="none";//LINK TRACKING
+hbx.dlf="n";//DOWNLOAD FILTER
+hbx.dft="n";//DOWNLOAD FILE NAMING
+hbx.elf="n";//EXIT LINK FILTER
+
+//SEGMENTS AND FUNNELS
+hbx.seg="";//VISITOR SEGMENTATION
+hbx.fnl="";//FUNNELS
+
+//CAMPAIGNS
+hbx.cmp="";//CAMPAIGN ID
+hbx.cmpn="";//CAMPAIGN ID IN QUERY
+hbx.dcmp="";//DYNAMIC CAMPAIGN ID
+hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY
+hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION
+hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION
+hbx.hra="";//RESPONSE ATTRIBUTE
+hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY
+hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY
+hbx.hlt="";//LEAD TRACKING
+hbx.hla="";//LEAD ATTRIBUTE
+hbx.gp="";//CAMPAIGN GOAL
+hbx.gpn="";//CAMPAIGN GOAL IN QUERY
+hbx.hcn="";//CONVERSION ATTRIBUTE
+hbx.hcv="";//CONVERSION VALUE
+hbx.cp="null";//LEGACY CAMPAIGN
+hbx.cpd="";//CAMPAIGN DOMAIN
+
+//CUSTOM VARIABLES
+hbx.ci="";//CUSTOMER ID
+hbx.hc1="";//CUSTOM 1
+hbx.hc2="";//CUSTOM 2
+hbx.hc3="";//CUSTOM 3
+hbx.hc4="";//CUSTOM 4
+hbx.hrf="";//CUSTOM REFERRER
+hbx.pec="";//ERROR CODES
+
+
+var cookieName = 'MyNokia';
+var nameEQ = cookieName + "=";
+var ca = document.cookie.split(';');
+for(var i=0;i < ca.length;i++) {
+ var c = ca[i];
+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
+ if (c.indexOf(nameEQ) == 0) {
+ hbx.ci = c.substring(nameEQ.length,c.length);
+ }
+}
+
+//INSERT CUSTOM EVENTS
+hbx.acct="DM550514HPNZ";
+hbx.mlc="/Home";
+hbx.pn="Home";
+hbx.lt="auto";
+
+
+//END EDITABLE SECTION
+
+//REQUIRED SECTION. CHANGE "YOURSERVER" TO VALID LOCATION ON YOUR WEB SERVER (HTTPS IF FROM SECURE SERVER)
+</script><script language="javascript1.1" defer src="/Hitbox/hbx_5.js"></script>
+<script language="javascript">if(navigator.appName!='Netscape'&&parseInt(navigator.appVersion)==4)document.write("<\!"+"--")</script><noscript>
+<img src="http://ehg-nokiafin.hitbox.com/HG?hc=we88&cd=1&hv=6&ce=u&hb=DM550514HPNZ&n=Home&vcon=/Home&seg=&cmp=&gp=&fnl=&pec=&dcmp=&ra=&gn=&cv=&ld=&la=&c1=&c2=&c3=&c4=&vpc=090101rn" border="0" width="1" height="1">
+</noscript><!--//-->
+
+<!--END WEBSIDESTORY CODE-->
+
+
+
+
+
+</head>
+<body lang='en'
+ style="margin: 0 0 0 0;" bgcolor="#FFFFFF" link="#0033cc" text="#000000" alink="#0033cc" vlink="#800080">
+ <div class="pagecontainer">
+
+
+<!-- start page template [Generated JSP Servlet: class=jsp_servlet._templates._page.__template6layout] -->
+
+
+
+
+
+
+
+
+
+
+ <!--startindex-->
+
+
+
+<!-- Begin template '/templates/content/plain.jsp' -->
+
+<div id="wayfinderContainer">
+ <div id="branding">
+ <img src="/NOKIA_COM_1/Home/Landing_page_2007/noflash_img/nokia_connecting_people.png" alt="Nokia - Connecting people" />
+
+ </div>
+
+ <div id="flashcontent">
+
+ <!-- main page noflash content -->
+ <div id="mainContentGlobal">
+ <div id="mainHdr"><h1>Welcome to Nokia</h1></div>
+ <div id="selectContainer">
+ <h2>Where would you like to go?</h2>
+ <div id="selectLinks">
+ <ul class="mainpage">
+ <li><a href="/A4176248">Africa</a></li>
+ <li><a href="/A4138125">Asia Pacific</a></li>
+ <li><a href="/A4138121">Europe</a></li>
+ <li><a href="/A4138127">Latin America</a></li>
+ <li><a href="/A4176245">Middle East</a></li>
+ <li><a href="/A4138126">North America</a></li>
+ </ul>
+ </div>
+ </div>
+ <!-- <a id="banner" href="http://www.nokia.com/seasonsgreetings/">Seasons Greetings</a> -->
+ </div>
+ <div id="navi">
+ <ul>
+ <li><a href="http://www.nokiaforbusiness.com/">Nokia for Business</a></li>
+ <li><a href="http://www.nokia.com/aboutnokia">About Nokia</a></li>
+ <li><a href="http://www.nokia.com/developers">Developers</a></li>
+ <li><a href="http://www.nokia.com/press">Press</a></li>
+ <li class="lastitem"><a href="http://www.nokia.com/investors">Investors</a></li>
+ <!-- <li class="lastitem"><a href="http://www.nokia.com/environment">Environment</a></li> -->
+ </ul>
+ </div>
+ <!-- noflash content ends -->
+
+ </div>
+
+ <div id="footer">
+ <ul>
+ <li><a href="http://www.nokia.com/siteterms">Site Terms</a></li>
+ <li class="lastitem"><a href="http://www.nokia.com/privacypolicy">Privacy Policy</a></li>
+ <span>Copyright &copy; 2008 Nokia. All rights reserved</span>
+ </ul>
+ <br /><br />
+ </div>
+</div>
+
+<script type="text/javascript" src="/NOKIA_COM_1/javascript/flash_detection_main.js"></script> <!-- for redirection to mobile site -->
+<script type="text/javascript" src="/EUROPE_NOKIA_COM_3/flash/swfobject.js"></script>
+<script type="text/javascript" src="/NOKIA_COM_1/javascript/cookies.js"></script>
+<script type="text/javascript" >
+ // <![CDATA[
+ var so = new SWFObject("/NOKIA_COM_1/Home/Landing_page_2007/wayfinder_assets.swf", "wayfinder", "736", "560", "7");
+ so.addParam("allowscriptaccess", "always");
+ so.addParam("base", "/NOKIA_COM_1/Home/Landing_page_2007/");
+ so.write("flashcontent");
+ // ]]>
+</script>
+
+<!-- End template '/templates/content/plain.jsp' -->
+ <!--stopindex-->
+
+
+
+
+
+ </div>
+</body>
+
+
+ </html>
+
diff --git a/examples/xml/htmlinfo/simpleexample.html b/examples/xml/htmlinfo/simpleexample.html
new file mode 100644
index 0000000000..83a55cf00a
--- /dev/null
+++ b/examples/xml/htmlinfo/simpleexample.html
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html>
+ <head>
+ <title>Qt is cute! Frans is too!</title>
+ </head>
+ <body>
+ <p>A paragraph.</p>
+ <p>A second paragraph. Check out our <a href="http://labs.qt.nokia.com/">developer blogs</a></p>
+ <p>And the last paragraph. Or our <a href="http://qt.nokia.com/doc/">online documentation</a>.</p>
+ </body>
+</html>
diff --git a/examples/xml/htmlinfo/trolltech_com.html b/examples/xml/htmlinfo/trolltech_com.html
new file mode 100644
index 0000000000..180eb74358
--- /dev/null
+++ b/examples/xml/htmlinfo/trolltech_com.html
@@ -0,0 +1,955 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+
+ <head>
+ <meta http-equiv="Content-Type"
+ content="text/html;charset=utf-8" />
+
+ <title>
+ Code Less. Create More. Deploy Everywhere.
+ &mdash;
+ Trolltech
+ </title>
+
+
+ <!-- ADD ON UPDATE -->
+
+ <meta name="author" content="Trolltech" />
+ <meta name="description"
+ content="Trolltech creates application development platforms for desktop and mobile device innovation." />
+ <meta name="keywords" content="" />
+
+<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"><!-- &nbsp;--></script>
+<script type="text/javascript">
+ <!-- Urchin script
+ _uacct = "UA-4457116-1";
+ urchinTracker();
+ -->
+ </script>
+
+ <base href="http://trolltech.com/homepage" />
+
+
+
+ <meta name="generator" content="Plone - http://plone.org" />
+
+
+ <!-- Plone ECMAScripts -->
+
+
+
+
+ <script type="text/javascript"
+ src="http://trolltech.com/portal_javascripts/TTSkin/ploneScripts2804.js">
+ </script>
+
+
+
+ <script type="text/javascript"
+ src="http://trolltech.com/portal_javascripts/TTSkin/ploneScripts0445.js">
+ </script>
+
+
+
+ <script type="text/javascript"
+ src="http://trolltech.com/portal_javascripts/TTSkin/ploneScripts5940.js">
+ </script>
+
+
+
+ <script type="text/javascript"
+ src="http://trolltech.com/portal_javascripts/TTSkin/linkpopper.js">
+ </script>
+
+
+
+ <script type="text/javascript"
+ src="http://trolltech.com/portal_javascripts/TTSkin/ploneScripts7743.js">
+ </script>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <style type="text/css"><!-- @import url(http://trolltech.com/portal_css/TTSkin/ploneStyles1145.css); --></style>
+
+
+
+
+
+
+
+
+ <style type="text/css"
+ media="screen"><!-- @import url(http://trolltech.com/portal_css/TTSkin/ploneStyles8707.css); --></style>
+
+
+
+
+
+
+
+
+
+
+ <!-- Internet Explorer CSS Fixes -->
+ <!--[if IE]>
+ <style type="text/css" media="all">@import url(http://trolltech.com/IEFixes.css);</style>
+ <![endif]-->
+
+ <link rel="shortcut icon" type="image/x-icon"
+ href="http://trolltech.com/favicon.ico" />
+
+ <link rel="home" href="http://trolltech.com"
+ title="Front page" />
+ <link rel="search"
+ href="http://trolltech.com/search_form"
+ title="Search this site" />
+ <link rel="author"
+ href="http://trolltech.com/author/admin"
+ title="Author information" />
+ <link rel="contents" href="http://trolltech.com/sitemap"
+ title="Site Map" />
+
+
+
+
+
+
+
+
+
+ <!-- Disable IE6 image toolbar -->
+ <meta http-equiv="imagetoolbar" content="no" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ </head>
+
+ <body class="section-homepage" dir="ltr">
+ <div id="visual-portal-wrapper">
+ <div id="portal-top">
+
+ <div id="portal-header">
+ <a class="hiddenStructure" accesskey="2"
+ href="http://trolltech.com/#documentContent">Skip to content.</a>
+
+ <a class="hiddenStructure" accesskey="6"
+ href="http://trolltech.com/#portlet-navigation-tree">Skip to navigation</a>
+
+ <div class="middlesex">
+ <ul id="portal-siteactions">
+
+ <li id="siteaction-sitemap"><a
+ href="http://trolltech.com/sitemap" accesskey="3"
+ title="Site Map">Site Map</a></li>
+ <li id="siteaction-accessibility"><a
+ href="http://trolltech.com/accessibility-info"
+ accesskey="0" title="Accessibility">Accessibility</a></li>
+ <li id="siteaction-contact"><a
+ href="http://trolltech.com/contact" accesskey="9"
+ title="Contact">Contact</a></li>
+
+</ul>
+
+ <div id="portal-searchbox">
+ <form name="searchform"
+ action="http://trolltech.com/search"
+ style="white-space:nowrap"
+ onsubmit="return liveSearchSubmit()">
+
+ <label for="searchGadget" class="hiddenStructure">Search Site</label>
+
+ <div class="LSBox">
+ <input id="searchGadget" name="SearchableText"
+ type="text" size="15" title="Search Site"
+ accesskey="4" class="visibility:visible" />
+
+ <input class="searchButton" type="submit"
+ value="Search" />
+
+ <div class="LSResult" id="LSResult" style=""><div class="LSShadow" id="LSShadow"></div></div>
+ </div>
+ </form>
+
+ <div id="portal-advanced-search" class="hiddenStructure">
+ <a href="http://trolltech.com/search_form"
+ accesskey="5">
+ Advanced Search&hellip;
+ </a>
+ </div>
+
+</div>
+
+ <div id="country-flags">
+ <a href="/lang/cn/"><img class="flag"
+ border="0" width="30" height="20" src="chineseflag.png" /></a>
+ <a href="/lang/japanese/"><img
+ class="flag" border="0" width="30" height="20"
+ src="japaneseflag.png" /></a>
+ </div>
+ <h1 id="portal-logo">
+ <a href="http://trolltech.com" accesskey="1">Trolltech</a>
+</h1>
+
+ <div id="portal-skinswitcher">
+
+</div>
+ </div>
+
+
+ <h5 class="hiddenStructure">Sections</h5>
+ <div id="portal-globalnav">
+ <div class="middlesex">
+ <ul>
+ <li id="portaltab-index_html"
+ class="selected indextab"><a
+ href="http://trolltech.com">Home</a></li>
+
+ <li id="portaltab-products"
+ class="plain"><a
+ href="http://trolltech.com/products" title="">Products and Services</a></li>
+
+
+ <li id="portaltab-solutions"
+ class="plain"><a
+ href="http://trolltech.com/solutions" title="">Solutions</a></li>
+
+
+ <li id="portaltab-developer"
+ class="plain"><a
+ href="http://trolltech.com/developer" title="">Developer Resources</a></li>
+
+
+ <li id="portaltab-company" class="plain"><a
+ href="http://trolltech.com/company" title="">Company</a></li>
+
+
+ <li id="portaltab-downloads"
+ class="plain"><a
+ href="http://trolltech.com/downloads" title="">Downloads</a></li>
+
+
+
+
+ </ul>
+ </div>
+ </div>
+
+ </div>
+ <div id="portal-personaltools-wrapper">
+
+<h5 class="hiddenStructure">Personal tools</h5>
+
+
+</div>
+
+ <div class="middlesex">
+ <div id="portal-breadcrumbs">
+
+ <span id="breadcrumbs-you-are-here">You
+are here:</span>
+ <a href="http://trolltech.com">Home</a>
+
+
+</div>
+ </div>
+ </div>
+
+ <div class="visualClear"><!-- --></div>
+
+
+ <table id="portal-columns">
+ <tbody>
+ <tr>
+
+
+
+
+
+ <td id="portal-column-content">
+
+
+ <div id="content" class="">
+
+
+
+ <div class="documentContent" id="region-content">
+
+ <a name="documentContent"></a>
+
+
+
+
+
+
+
+
+
+
+
+ <!-- <table id="frontpagetable" cellpadding="0" cellspacing="0" tal:attributes="width pagew"> --> <!-- tal:on-error="string:replace with error template" Fetch image width here -->
+ <table id="frontpagetable" cellpadding="0"
+ cellspacing="0" width="712">
+ <tr>
+ <td colspan="2">
+
+ <h2>Trolltech provides cross-platform software solutions for:</h2>
+ <table id="fpSolutions" class="solutions" cellpadding="0" cellspacing="6" width="100%">
+ <tbody>
+ <tr>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/managing-development">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Software Development Managers</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/industrial-embedded-development">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Embedded Developers</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+
+ </tr>
+ <tr>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/ce-mobile-vendors">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Consumer Electronics Vendors</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/mobile-application-development">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Mobile Application Developers</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+
+ </tr>
+ <tr>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/application-development">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Cross-Platform Developers</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+ <td>
+ <!-- GRANTHAM STYLE -->
+ <a class="roundedButton"
+ title=""
+ href="http://trolltech.com/solutions/solutions-opensource">
+ <span class="buttonTop"><span class="roundedButtonTL"><span class="roundedButtonTR"></span></span></span>
+ <span class="buttonLeft">
+ <span class="buttonRight"><span
+ class="buttonArrow">Open Source Developers</span></span>
+ </span>
+ <span class="buttonBottom"><span class="roundedButtonBL"><span class="roundedButtonBR"></span></span></span>
+ </a>
+ <!-- OLD STYLE
+ <div class="roundedBlock"
+ tal:attributes="title python:solution.Description();
+ class python:test(repeat['solution'].odd(), 'roundedBlock odd', 'roundedBlock')">
+ <span class="portletTopLeft"></span>
+ <span class="portletTopRight"></span>
+ <div class="innerRoundedBlock">
+ <a href="#"
+ tal:attributes="href python:solution.absolute_url()">
+ <span class="arrow"></span>
+ <strong tal:content="python:solution.Title()">
+ Title
+ </strong>
+ </a>
+ </div>
+ <span class="portletBottomLeft"></span>
+ <span class="portletBottomRight"></span>
+ </div>
+ -->
+ </td>
+
+ </tr>
+ </tbody>
+ </table>
+
+ </td>
+ </tr>
+
+ <!-- BANNER -->
+
+ <tr class="minspacerow">
+ <td colspan="2">
+
+ <div id="flashcontent">
+
+
+ <!-- In case of no imagemap -->
+ <a
+ href="http://trolltech.com/products/qt/learnmore/whitepapers">
+ <img border="0"
+ src="http://trolltech.com/include/features/frontpage/whitepaper-feature/mainsplash"
+ alt="Code Less. Create More. Deploy Everywhere."
+ height="100" width="700" />
+ </a>
+
+
+ </div>
+
+
+
+ </td>
+ </tr>
+
+ <!-- Product Feature rows -->
+ <tr id="productfeatures" class="minspacerow">
+ <td style="width:350px;">
+ <div class="viewlet productviewlet">
+<p class="discreet"><a title="Downloads" href="downloads/index"><img class="image-right" src="images/frontpage/qt_download_90.png" alt="Download Qt Button: Grey BG" /></a></p>
+<h2>Qt</h2>
+<p>Qt is a cross-platform application framework.&nbsp; It includes:</p>
+<ul><li>An <a title="C++ Class Library" href="products/qt/features/library/index">intuitive class library</a></li><li>Integrated <a title="Development Tools" href="products/qt/features/tools/index">development tools</a></li><li>Support for <a title="C++ and Java Support" href="products/qt/features/language-support/index">C++ and Java development</a></li><li><a title="Cross-Platform Development" href="products/qt/features/platforms/index">Desktop and embedded</a> development support</li></ul>
+<p>&nbsp;</p>
+<p><strong><a title="Qt Cross-Platform Application Framework" href="products/qt/index"><span class="button">Learn More</span></a></strong> <strong><a title="How to order" href="products/qt/orderform"><span class="button">Buy Now</span></a></strong></p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+<p>&nbsp;</p>
+</div>
+ </td>
+ <td style="width:350px;">
+ <div class="viewlet productviewlet">
+<p><a title="Qtopia" href="products/qtopia"><img class="image-right" src="images/frontpage/qtopia_learn_more_90.png" alt="Qtopia Learn More button 90px" /></a></p>
+<h2>Qtopia</h2>
+<p><a title="The Qtopia application platform for embedded Linux" href="products/qtopia/index">Qtopia</a> is an application platform and UI for Linux-based <a title="Qtopia Phone Edition" href="products/qtopia/qtopia-product-family/qtopia-phone-edition">mobile</a>, <a title="Qtopia Platform" href="products/qtopia/qtopia-product-family/qtopia-platform">consumer electronics</a> and <a title="Qtopia Platform" href="products/qtopia/qtopia-product-family/qtopia-platform">embedded devices</a>. Qtopia offers:</p>
+<ul><li>Rich <a href="products/qt/features/tools/index">toolkit</a> and intuitive API</li><li>Fully customizable user interface</li><li>Highly efficient development framework</li></ul>
+<p>&nbsp;</p>
+<p><strong><a title="Customer Devices" href="company/customers/customer-devices"><span class="button">Customer Devices</span></a></strong>&nbsp;<strong><a title="Purchasing Qtopia" href="products/qtopia/orderinfo"><span class="button">Buy Now</span></a></strong></p>
+</div>
+ </td>
+ </tr>
+ </table>
+
+
+
+
+
+
+
+
+
+
+
+
+ </div>
+
+ </div>
+
+
+ </td>
+
+
+
+
+ <!-- News/events -->
+ <td id="frontpage-column-two">
+
+ <div class="viewlet">
+ <h3>Quick Links</h3>
+
+
+ <!-- Smart folders -->
+
+ <!-- Links -->
+
+ <p class="smallerExtendedLink">
+ <a href="http://trolltech.com/company/careers"
+ title="Quick Links">Careers at Trolltech</a>
+ </p>
+
+
+ <p class="smallerExtendedLink">
+ <a href="http://trolltech.com/products/qt/learnmore/whitepapers"
+ title="Quick Links">Whitepapers</a>
+ </p>
+
+
+ <p class="smallerExtendedLink">
+ <a href="http://trolltech.com/products/qt/learnmore/webinars-videos"
+ title="Quick Links">Webinars and Videos</a>
+ </p>
+
+ </div>
+
+
+ <div class="viewlet">
+ <h3>Nokia Acquisition</h3>
+
+ <div class="viewletBody">
+<p class="smallerExtendedLink"><a title="Nokia Acquires Trolltech" href="../../../28012008/28012008">Learn more about Nokia's acquisition of Trolltech<br /></a></p>
+</div>
+ <!-- Smart folders -->
+
+ <!-- Links -->
+
+
+
+ </div>
+
+
+ <div class="viewlet">
+ <h3>News</h3>
+
+
+ <!-- Smart folders -->
+
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/announcements/press.2008-06-03.1419977468">Trolltech Releases Qt Jambi 4.3.5</a>
+ <!-- Dates for press release -->
+
+
+ (Jun&nbsp;03)
+ <!--(<tal:date tal:content="item_pressmonth"/>&nbsp;<tal:date tal:content="item_pressday"/>)-->
+
+
+ <!-- Dates for events -->
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/announcements/press.2008-05-28.9662742780">Trolltech releases Qt 4.3.5</a>
+ <!-- Dates for press release -->
+
+
+ (May&nbsp;28)
+ <!--(<tal:date tal:content="item_pressmonth"/>&nbsp;<tal:date tal:content="item_pressday"/>)-->
+
+
+ <!-- Dates for events -->
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/announcements/press.2008-05-14.1108908046">Award From Qt Developers Recognizes Best Open Source Development Tools</a>
+ <!-- Dates for press release -->
+
+
+ (May&nbsp;14)
+ <!--(<tal:date tal:content="item_pressmonth"/>&nbsp;<tal:date tal:content="item_pressday"/>)-->
+
+
+ <!-- Dates for events -->
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/announcements/press.2008-05-08.1819339587">Trolltech Delivered Revenues of NOK 55.6 Million</a>
+ <!-- Dates for press release -->
+
+
+ (May&nbsp;08)
+ <!--(<tal:date tal:content="item_pressmonth"/>&nbsp;<tal:date tal:content="item_pressday"/>)-->
+
+
+ <!-- Dates for events -->
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+
+ <!-- Links -->
+
+
+
+ </div>
+
+
+ <div class="viewlet">
+ <h3>Events</h3>
+
+ <div class="viewletBody">
+<p>&nbsp;</p>
+</div>
+ <!-- Smart folders -->
+
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/events/allevents/event.2008-05-15.0963129132">Qt Open Enrollment Training Class</a>
+ <!-- Dates for press release -->
+
+ <!-- Dates for events -->
+
+
+ (Jun&nbsp;09&nbsp;-&nbsp;Jun&nbsp;13)
+
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/events/allevents/event.2008-02-22.1032431617">Israel Qt User Group</a>
+ <!-- Dates for press release -->
+
+ <!-- Dates for events -->
+
+
+ (Jun&nbsp;16)
+
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+ <p class="smallerFont">
+ <span>
+ <a href="http://trolltech.com/company/newsroom/events/allevents/event.2008-05-19.5707721007">Webinar: Building Tomorrow’s Virtual Driver Control Center</a>
+ <!-- Dates for press release -->
+
+ <!-- Dates for events -->
+
+
+ (Jun&nbsp;24)
+
+
+ <!-- Dates for training -->
+
+ </span>
+ </p>
+
+ <!-- Links -->
+
+ <p class="smallerExtendedLink">
+ <a href="http://trolltech.com/company/newsroom/events"
+ title="Events">More events</a>
+ </p>
+
+
+
+ </div>
+
+ </td>
+
+
+ </tr>
+ </tbody>
+ </table>
+
+
+ <div class="visualClear"><!-- --></div>
+
+
+ <hr class="netscape4" />
+
+
+
+ <div id="portal-footer">
+
+
+<p id="bottom-navigation">
+ Trolltech&reg; - Code Less. Create More. Deploy Everywhere.
+
+ <br />
+
+ <a href="http://trolltech.com/company/contact-us/locations"
+ title="Trolltech ASA">
+ Trolltech ASA
+ </a>
+ <a href="http://trolltech.com/company/contact-us/locations"
+ title="Address: Sandakerveien 116, Oslo">
+ Sandakerveien 116, Oslo
+ </a>
+ <a href="http://trolltech.com/company/contact-us/locations"
+ class="lastNavItem" title="Phone: +47 21 60 48 00">
+ +47 21 60 48 00
+ </a>
+
+ <br />
+
+ <a href="http://trolltech.com/company/contact-us/locations"
+ title="International locations">
+ International locations
+ </a>
+ <a href="/trolltech/privacypolicy" title="Privacy policy">
+ Privacy Policy
+ </a>
+ <a href="/trolltech/copyright" title="Trolltech" class="lastNavItem"><span>2008</span> &copy; Trolltech ASA</a>
+</p>
+
+
+</div>
+
+ <div id="portal-colophon">
+
+
+ <a href="http://plone.org"
+ class="colophonIcon colophonIconPlone"
+ title="This Plone site was built using Plone CMS, the Open Source Content Management System. Click for more information.">
+ Powered by Plone CMS, the Open Source Content Management System
+ </a>
+
+
+
+ <p class="discreet">
+ This site conforms to the following standards:
+ </p>
+
+ <div class="colophonWrapper">
+ <ul>
+ <li>
+ <a href="http://www.section508.gov"
+ class="colophonIcon colophonIcon508"
+ title="This Plone site conforms to the US Government Section 508 Accessibility Guidelines.">
+ Section 508
+ </a>
+ </li>
+ <li>
+ <a href="http://www.w3.org/WAI/WCAG1AA-Conformance"
+ class="colophonIcon colophonIconWAI"
+ title="This Plone site conforms to the W3C-WAI Web Content Accessibility Guidelines.">
+ WCAG
+ </a>
+ </li>
+ <li>
+ <a href="http://validator.w3.org/check/referer"
+ class="colophonIcon colophonIconXHTML"
+ title="This Plone site is valid XHTML.">
+ Valid XHTML
+ </a>
+ </li>
+ <li>
+ <a href="http://jigsaw.w3.org/css-validator/check/referer&amp;warning=no&amp;profile=css3&amp;usermedium=all"
+ class="colophonIcon colophonIconCSS"
+ title="This Plone site was built with valid CSS.">
+ Valid CSS
+ </a>
+ </li>
+ <li>
+ <a href="http://plone.org/browsersupport"
+ class="colophonIcon colophonIconAnyBrowser"
+ title="This Plone site is usable in any web browser.">
+ Usable in any browser
+ </a>
+ </li>
+ </ul>
+ </div>
+
+ </div>
+
+ </div>
+<!-- ProspectXtractor tracker script -->
+<script type="text/javascript"><!--
+function _pxPar()
+{
+var p="";
+p+="&ref="+escape(top.document.referrer);
+p+="&dt="+escape(document.title);
+p+="&sr="+screen.width+"x"+screen.height;
+p+="&sd="+screen.colorDepth;
+p+="&fv="+_pxFV();
+return p;
+}
+function _pxFV()
+{
+var f=0,n=navigator;
+if (n.plugins && n.mimeTypes.length) {
+var x=n.plugins["Shockwave Flash"];
+if(x && x.description) {
+var y=x.description;
+f=y.charAt(y.indexOf('.')-1);
+}
+} else {
+r=false;
+for(var i=15;i>=3&&r!=true;i-=1){
+execScript('on error resume next: r=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
+f=i;
+}
+}
+return f;
+}
+document.write('<img src="http://pxreg.onlineservicesas.com/pxreg/?id=50C9FD2F-61D5-4824-B726-50D6B1F89999'+_pxPar()+'" width="1" heigth="1" />');
+//-->
+</script>
+<noscript>
+<div><img src="http://pxreg.onlineservicesas.com/pxreg/?id=50C9FD2F-61D5-4824-B726-50D6B1F89999" width="1" height="1" alt="" /></div>
+</noscript>
+<!-- END ProspectXtractor tracker script -->
+</body>
+</html>
+
diff --git a/examples/xml/htmlinfo/w3c_org.html b/examples/xml/htmlinfo/w3c_org.html
new file mode 100644
index 0000000000..0fcce48e4a
--- /dev/null
+++ b/examples/xml/htmlinfo/w3c_org.html
@@ -0,0 +1,507 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
+<head profile="http://www.w3.org/2000/08/w3c-synd/#"><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="HTML Tidy for Mac OS X (vers 1st March 2004), see www.w3.org" />
+
+<meta name="keywords" content="W3C, World Wide Web, Web, WWW, Consortium, computer, access, accessibility, semantic, worldwide, W3, HTML, XML, standard, language, technology, link, CSS, RDF, XSL, Berners-Lee, Berners, Lee, style sheet, cascading, schema, XHTML, mobile, SVG, PNG, PICS, DOM, SMIL, MathML, markup, Amaya, Jigsaw, free, open source, software" />
+<meta name="description" content="The World Wide Web Consortium (W3C) is an international consortium where Member organizations, a full-time staff, and the public work together to develop Web standards. W3C primarily pursues its mission through the creation of Web standards and guidelines designed to ensure long-term growth for the Web. Over 400 organizations are Members of the Consortium. W3C is jointly run by the MIT Computer Science and Artificial Intelligence Laboratory (MIT CSAIL) in the USA, the European Research Consortium for Informatics and Mathematics (ERCIM) headquartered in France, Keio University in Japan, and has additional Offices worldwide." />
+
+<title>World Wide Web Consortium - Web Standards</title>
+<link rel="meta" href="/Overview-about.rdf" />
+<link rel="stylesheet" type="text/css" href="/StyleSheets/home.css" />
+<link rel="bookmark" href="#technologies" title="Technologies |" />
+<link rel="bookmark" href="#news" title="News |" />
+<link rel="bookmark" href="#search" title="Search |" />
+<link rel="contents" href="#contents" title="Contents |" />
+<link rel="bookmark" href="#Offices" title="Offices |" />
+<link rel="bookmark" href="#systems" title="Systems |" />
+<link rel="bookmark" href="#donors" title="Supporters |" />
+<link rel="bookmark" href="#footnotes" title="Footnotes |" />
+<link rel="alternate" type="application/rss+xml" title="W3C Home Page News RSS Channel" href="http://www.w3.org/2000/08/w3c-synd/home.rss" />
+
+<style type="text/css">
+/**/
+ div.spot-image img {
+ margin-bottom: 20px;
+ }
+/**/
+</style>
+</head>
+
+<body>
+<h1 id="logo"><img alt="The World Wide Web Consortium (W3C)" height="48" width="315" src="/Icons/w3c_main" /></h1>
+
+<h2 id="slogan">Leading the Web to Its Full Potential...</h2>
+
+<div>
+<map name="introLinks" id="introLinks" title="Introductory Links">
+<div class="banner">
+<span class="invisible"><a class="bannerLink" title="Skip introductory links and the mission statement" href="#technologies">Skip to Technologies</a> |</span> <a class="bannerLink" title="W3C Activities" accesskey="A" href="/Consortium/activities">Activities</a> | <a class="bannerLink" title="Technical Reports and Recommendations" accesskey="T" href="/TR/">Technical Reports</a> | <a class="bannerLink" title="Alphabetical Site Index" accesskey="S" href="/Consortium/siteindex">Site Index</a> | <a class="bannerLink" title="Help for new visitors" accesskey="N" href="/Consortium/new-to-w3c">New
+Visitors</a> | <a class="bannerLink" title="About W3C" accesskey="B" href="/Consortium/">About W3C</a> | <a class="bannerLink" title="Join W3C" accesskey="J" href="/Consortium/join">Join W3C</a> |
+<a class="bannerLink" title="Contact W3C" accesskey="C" href="/Consortium/contact">Contact W3C</a>
+</div>
+</map>
+</div>
+
+<p class="small">The World Wide Web Consortium (<acronym title="World Wide Web Consortium">W3C</acronym>) develops interoperable
+technologies (specifications, guidelines, software, and tools) to lead
+the Web to its full potential. W3C is a forum for information,
+commerce, communication, and collective understanding. On this page,
+you'll find <a href="#news">W3C news</a>, links to <a href="#technologies">W3C technologies</a> and ways to <a href="#contents">get involved</a>. New visitors can find help in
+<cite><a href="/Consortium/new-to-w3c">Finding Your Way at
+W3C</a></cite>. We encourage organizations to learn more <a href="/Consortium/">about W3C</a> and <a href="/Consortium/membership">about
+W3C Membership</a>.</p>
+
+<div class="navBlock">
+<h2 class="spot-head">XML10</h2>
+
+<div class="spot">
+<div class="spot-image">
+<a href="/2008/xml10/">
+<img src="/2008/xml10/xml-10.png" width="106" height="48" alt="XML 10" />
+</a>
+</div>
+<p class="spot-block">
+To celebrate
+<a href="/2008/xml10/">ten years of XML</a>,
+W3C invites you to
+<a href="/2008/xml10/card/greeting-form">send a greeting</a>
+and tell us about an XML-related blog or article.
+Many thanks to the FLWOR Foundation for their
+generous sponsorship of XML10.
+</p>
+</div>
+
+<h2 class="spot-head">W3C Supporters</h2>
+<div class="spot">
+<p class="spot-block">Help W3C by making a donation through the
+<a href="/Consortium/sup">W3C Supporters Program</a>.</p>
+</div>
+
+
+
+<h2 class="spot-head">Employment</h2>
+
+<div class="spot">
+<p class="spot-block">Current <a href="/Consortium/Recruitment/">job
+opportunities</a> at W3C: <a href="http://www.ercim.org/jobs/wai_consultant.html">Web Accessibility and Ageing Consultant</a>. Current <a href="/Consortium/Recruitment/Fellows#openings">W3C Fellows Program
+openings</a> are <a href="/2007/01/comm-fellow1">Business and
+Technology Communications Specialist</a>, <a href="/2007/01/comm-fellow2">Web / Graphic Designer</a>, and <a href="/2007/01/SysteamFellowsPosition">Software Engineer</a>.</p>
+</div>
+
+<h2 class="navhead"><a name="technologies" id="technologies">W3C A to
+Z</a></h2>
+
+<ul>
+<li class="invisible"><a class="navlink" title="Skip W3C A-Z" href="#news">Skip to News</a></li>
+
+<li><a href="/WAI/" class="navlink">Accessibility</a></li>
+
+<li><a href="/Amaya/" class="navlink">Amaya</a></li>
+
+<li><a href="/Mobile/CCPP/" class="navlink"><abbr title="Composite Capability/Preference Profiles">CC/PP</abbr></a></li>
+
+<li><a href="/2004/CDF/" class="navlink">Compound Document Formats
+(CDF)</a></li>
+
+<li><a href="/Style/CSS/" class="navlink"><abbr title="Cascading Style Sheets">CSS</abbr></a></li>
+
+<li><a href="http://jigsaw.w3.org/css-validator/" class="navlink"><abbr title="Cascading Style Sheets">CSS</abbr>
+Validator</a></li>
+
+<li><a href="/2002/ws/databinding/" class="navlink">Databinding</a></li>
+
+<li><a href="/DOM/" class="navlink"><acronym title="Document Object Model">DOM</acronym></a></li>
+
+<li><a href="/XML/EXI" class="navlink">Efficient XML
+Interchange</a></li>
+
+<li><a href="/2007/eGov/" class="navlink">eGovernment</a></li>
+
+<li><a href="/2001/sw/grddl-wg/" class="navlink"><acronym title="Gleaning Resource Descriptions from Dialects of Languages">GRDDL</acronym></a></li>
+
+<li><a href="/2001/sw/hcls/" class="navlink">Health Care and Life
+Sciences</a></li>
+
+<li><a href="/html/" class="navlink"><abbr title="HyperText Markup Language">HTML</abbr></a></li>
+
+<li><a href="/People/Raggett/tidy/" class="navlink"><abbr title="HyperText Markup Language">HTML</abbr> Tidy</a></li>
+
+<li><a href="http://validator.w3.org/" class="navlink"><abbr title="HyperText Markup Language">HTML</abbr> Validator</a></li>
+
+<li><a href="/Protocols/" class="navlink"><abbr title="Hypertext Transfer Protocol">HTTP</abbr></a></li>
+
+<li><a href="/2005/Incubator/" class="navlink">Incubator</a></li>
+
+<li><a href="/2002/mmi/ink" class="navlink">InkML</a></li>
+
+<li><a href="/International/" class="navlink">Internationalization</a></li>
+
+<li><a href="/Jigsaw/" class="navlink">Jigsaw</a></li>
+
+<li><a href="/Library/" class="navlink">Libwww</a></li>
+
+<li><a href="/Math/" class="navlink">MathML</a></li>
+
+<li><a href="/Mobile/" class="navlink">Mobile Web Initiative
+(W3C-MWI)</a></li>
+
+<li><a href="/2002/mmi/" class="navlink">Multimodal
+Interaction</a></li>
+
+<li><a href="/2004/OWL/" class="navlink"><acronym title="OWL Web Ontology Language">OWL</acronym></a></li>
+
+<li><a href="/2004/pp/" class="navlink">Patent Policy</a></li>
+
+<li><a href="/PICS/" class="navlink"><acronym title="Platform for Internet Content Selection">PICS</acronym></a></li>
+
+<li><a href="/Graphics/PNG/" class="navlink"><acronym title="Portable Network Graphics">PNG</acronym></a></li>
+
+<li><a href="/2007/powder/" class="navlink"><acronym title="Protocol for Web Description Resources">POWDER</acronym></a></li>
+
+<li><a href="/P3P/" class="navlink">Privacy and <abbr title="Platform for Privacy Preferences">P3P</abbr></a></li>
+
+<li><a href="/RDF/" class="navlink"><abbr title="Resource Description Framework">RDF</abbr></a></li>
+
+<li><a href="/2006/rwc/" class="navlink">Rich Web Clients</a></li>
+
+<li><a href="/2005/rules/" class="navlink">Rules</a></li>
+
+<li><a href="/Security/" class="navlink">Security</a></li>
+
+<li><a href="/2001/sw/" class="navlink">Semantic Web</a></li>
+
+<li><a href="/XML/SML" class="navlink">Service Modeling Language
+(<abbr title="Service Modeling Language">SML</abbr>)</a></li>
+
+<li><a href="/AudioVideo/" class="navlink"><acronym title="Synchronized Multimedia Integration Language">SMIL</acronym></a></li>
+
+<li><a href="/2000/xp/Group/" class="navlink"><acronym title="Soap">SOAP</acronym>/<abbr title="XML Protocol">XMLP</abbr></a></li>
+
+<li><a href="/2002/ws/soapjms/" class="navlink"><acronym title="Soap">SOAP-JMS</acronym></a></li>
+
+<li><a href="/2001/sw/DataAccess/" class="navlink"><acronym title="Simple Protocol and RDF Query Language">SPARQL</acronym></a></li>
+
+<li><a href="/Style/" class="navlink">Style</a></li>
+
+<li><a href="/Graphics/SVG/" class="navlink"><abbr title="Scalable Vector Graphics">SVG</abbr></a></li>
+
+<li><a href="/2001/tag/" class="navlink"><abbr title="Technical Architecture Group">TAG</abbr></a></li>
+
+<li><a href="/AudioVideo/TT/" class="navlink">Timed Text</a></li>
+
+<li><a href="/Addressing/" class="navlink"><abbr title="Uniform Resource Identifiers">URI/URL</abbr></a></li>
+
+<li><a href="/QA/Tools/#validators" class="navlink">Validators</a></li>
+
+<li><a href="/Voice/" class="navlink">Voice</a></li>
+
+<li><a href="/2007/uwa/" class="navlink">Ubiquitous Web
+Applications</a></li>
+
+<li><a href="/WAI/" class="navlink"><acronym title="Web Accessibility Initiative">WAI</acronym></a></li>
+
+<li><a href="/2006/webapi/" class="navlink">Web API</a></li>
+
+<li><a href="/2006/appformats/" class="navlink">Web Application
+Formats</a></li>
+
+<li><a href="/2001/tag/" class="navlink">Web Architecture
+(<acronym title="Technical Architecture Group">TAG</acronym>)</a></li>
+
+<li><a href="/Graphics/WebCGM/WG/" class="navlink"><abbr title="Web Computer Graphics Metafile">WebCGM</abbr></a></li>
+
+<li><a href="/2002/ws/" class="navlink">Web Services</a></li>
+
+<li><a href="/2002/ws/addr/" class="navlink"><abbr title="Web Services">WS</abbr>-Addressing</a></li>
+
+<li><a href="/2002/ws/chor/" class="navlink"><abbr title="Web Services Choreography Description Language">WS-CDL</abbr></a></li>
+
+<li><a href="/2002/ws/desc/" class="navlink"><acronym title="Web Services Description Language">WSDL</acronym></a></li>
+
+<li><a href="/2002/ws/policy/" class="navlink"><abbr title="Web Services">WS</abbr>-Policy</a></li>
+
+<li><a href="/MarkUp/Forms/" class="navlink"><acronym title="Next Generation Web Forms">XForms</acronym></a></li>
+
+<li><a href="/MarkUp/" class="navlink"><abbr title="Extensible HyperText Markup Language">XHTML</abbr></a></li>
+
+<li><a href="/MarkUp/" class="navlink"><abbr title="Extensible HyperText Markup Language">XHTML2</abbr></a></li>
+
+<li><a href="/XML/Linking" class="navlink"><acronym title="XML Link">XLink</acronym></a></li>
+
+<li><a href="/XML/" class="navlink"><abbr title="Extensible Markup Language">XML</abbr></a></li>
+
+<li><a href="/TR/xmlbase/" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Base</a></li>
+
+<li><a href="/2001/XKMS/" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Key Management</a></li>
+
+<li><a href="/XML/Processing/" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Processing</a></li>
+
+<li><a href="/XML/Query" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Query</a></li>
+
+<li><a href="/XML/Schema" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Schema</a></li>
+
+<li><a href="/2008/xmlsec/" class="navlink"><abbr title="Extensible Markup Language">XML</abbr> Signature
+and Encryption</a></li>
+
+<li><a href="/Style/XSL/" class="navlink">XPath</a></li>
+
+<li><a href="/XML/Linking" class="navlink">XPointer</a></li>
+
+<li><a href="/Style/XSL/" class="navlink"><acronym title="Extensible Stylesheet Language">XSL</acronym> and <acronym title="XSL Transformations">XSLT</acronym></a></li>
+</ul>
+
+<p><a href="/Consortium/siteindex" class="navlink">More
+topics...</a></p>
+</div>
+
+<div class="newsBlock">
+<h2 class="newsHeading"><a name="news" id="news">News</a></h2>
+
+<p class="invisible"><a title="Skip News" href="#search">Skip to
+Search</a></p>
+
+<div id="item103" class="item"><h3 class="headline">New eGovernment Activity to Help Improve Government through Better Use of the Web</h3>
+<p><a href="/2007/eGov/"><img class="newsImage" width="300" height="75" src="/2008/06/03-egov" alt="Crowd scene" /></a></p>
+<p><span class="date">2008-06-03:</span> W3C launches today a <a href="/2007/eGov/">new forum</a> for governments, citizens, researchers, and other stakeholders to investigate how best to use Web technology for good governance and citizen participation. "Open Standards, and in particular Semantic Web Standards, can help lower the cost of government, make it easier for independent agencies to work together, and increase flexibility in the face of change," said Tim Berners-Lee, W3C Director. W3C invites participation in the new <a href="/2007/eGov/IG/">eGovernment Interest Group</a>, which is open to the public. The group will identify best practices and guidelines in this area, document where current technology does not adequately address stakeholder needs, and suggest improvements via the standards process. Read the <a href="/2007/eGov/IG/faq">W3C eGovernment FAQ</a> and <a href="/2008/06/egov-pressrelease">press release</a>, and learn more about the <a href="/2007/eGov/">W3C eGovernment Activity</a>.<span class="archive"> (<a title="New eGovernment Activity to Help Improve Government through Better Use of the Web" href="/News/2008#item103" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item105" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Two Group Notes Published About Semantic Web and Life Sciences</h3><p><span class="date">2008-06-05:</span> The <a href="/2001/sw/hcls/">Semantic Web Health Care and Life Sciences Interest Group</a> has published two Group Notes: <a href="/TR/2008/NOTE-hcls-kb-20080604/">A Prototype Knowledge Base for the Life Sciences</a> and <a href="/TR/2008/NOTE-hcls-senselab-20080604/">Experiences with the conversion of SenseLab databases to RDF/OWL</a>. The former describes a prototype of a biomedical knowledge base that integrates 15 distinct data sources using currently available Semantic Web technologies including RDF and OWL. The Note outlines which resources were integrated, how the knowledge base was constructed using free and open source triple store technology, how it can be queried using SPARQL, and what resources and inferences are involved in answering complex queries. While the utility of the knowledge base is illustrated by identifying a set of genes involved in Alzheimer's Disease, the approach described here can be applied to any use case that integrates data from multiple domains. The second document describe the experience of converting SenseLab databases into OWL, an important step towards realizing the benefits of Semantic Web in integrative neuroscience research. Learn more about the <a href="/2001/sw/">Semantic Web Activity</a>.<span class="archive"> (<a title="Two Group Notes Published About Semantic Web and Life Sciences" href="/News/2008#item105" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item104" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Offline Web Applications Published as W3C Note</h3><p><span class="date">2008-06-03:</span> The <a href="/html/wg/">HTML Working Group</a> has published the <a href="/TR/2008/NOTE-offline-webapps-20080530/">Offline Web Applications</a> Group Note. <a href="/TR/html5/">HTML 5</a> contains several features that address the challenge of building Web applications that work while offline. This document highlights these features (SQL, offline application caching APIs as well as online/offline events, status, and the localStorage API) from HTML 5 and provides brief tutorials on how these features might be used to create Web applications that work offline. Learn more about the <a href="/MarkUp/Activity">HTML Activity</a>.<span class="archive"> (<a title="Offline Web Applications Published as W3C Note" href="/News/2008#item104" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item102" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />W3C Advisory Committee Elects Advisory Board</h3><p><span class="date">2008-06-02:</span> The W3C Advisory Committee has filled six open seats on the <a href="/2002/ab/">W3C Advisory Board</a>. Created in 1998, the Advisory Board provides guidance to the Team on issues of strategy, management, legal matters, process, and conflict resolution. Beginning 1 July, the nine Advisory Board participants are Jean-François Abramatic (ILOG), Ann Bassetti (The Boeing Company), Jim Bell (HP), Don Deutsch (Oracle), Eduardo Gutentag (Sun Microsystems), Steve Holbrook (IBM), Ken Laskey (MITRE), Ora Lassila (Nokia), and Arun Ranganathan (Mozilla Foundation). Steve Zilles continues as interim Advisory Board Chair. Read more about the <a href="/2002/ab/">Advisory Board</a>.<span class="archive"> (<a title="W3C Advisory Committee Elects Advisory Board" href="/News/2008#item102" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item101" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />W3C Talks in June</h3><p><span class="date">2008-06-02:</span> Browse <a href="/Talks/">W3C presentations and events</a> also available as an <abbr title="RDF Site Summary"><a href="/2004/08/TalkFiles/Talks.rss">RSS channel</a></abbr>. <span class="archive"> (<a title="W3C Talks in June" href="/News/2008#item101" rel="details">Permalink</a>) </span></p><ul><li><span class="talkstart">2 June, Västerås, Sweden: </span><span class="talktitle" lang="sv" xml:lang="sv">Framtidssäkra eFörvaltningen<span class="hide noprint">.</span></span><span class="talkdesc">Olle Olsson participates in a panel at <a href="http://www.offentligarummet.se/" lang="sv" xml:lang="sv">Offentliga Rummet 2008</a>. </span></li><li><span class="talkstart">4 June, Sao Paulo, Brazil: </span><span class="talktitle">Towards eGovernment 2.0 through better use of the Web<span class="hide noprint">.</span></span><span class="talkdesc">José Manuel Alonso presents at <a href="http://www.w3c.br/2008/launch/">W3C Brazil Office Public Launch</a>. </span></li><li><span class="talkstart">4 June, Sao Paolo, Brazil: </span><span class="talktitle">W3C - Web Open Standards<span class="hide noprint">.</span></span><span class="talkdesc">Daniel Dardailler presents at <a href="http://www.w3c.br/2008/lancamento/">W3C Brazil Office Launch event </a>. </span></li><li><span class="talkstart">10 June, Buenos Aires, Argentina: </span><span class="talktitle">Web Accessibility: People with Disabilities and Elderly Citizens<span class="hide noprint">.</span></span><span class="talkdesc">Shadi Abou-Zahra presents at <a href="http://www.isoc.org.ar/accesibilidad.html" lang="es" xml:lang="es">Web Sin Barreras</a>. </span></li><li><span class="talkstart">11 June, Nashville, TN, USA: </span><span class="talktitle">Color for the Global Web<span class="hide noprint">.</span></span><span class="talkdesc">Molly E Holzschlag presents at <a href="http://www.voicesthatmatter.com/webdesign2008/index.aspx">Voices That Matter</a>. </span></li><li><span class="talkstart">12 June, Nashville, TN, USA: </span><span class="talktitle">Designing for Today's Browsers<span class="hide noprint">.</span></span><span class="talkdesc">Molly E Holzschlag presents at <a href="http://www.voicesthatmatter.com/webdesign2008/index.aspx">Voices That Matter</a>. </span></li><li><span class="talkstart">17 June, New York, NY, USA: </span><span class="talktitle">Web of Data<span class="hide noprint">.</span></span><span class="talkdesc">Tim Berners-Lee presents at <a href="http://www.linkeddataplanet.com/index.php">LinkedData Planet Conference: exploring the new web of linked data</a>. </span></li><li><span class="talkstart">19 June, Tokyo, Japan: </span><span class="talktitle">Update on W3C/WAI Guidelines including WCAG 2.0<span class="hide noprint">.</span></span><span class="talkdesc">Judy Brewer presents at <a>Open Seminar of Information Accessibility</a>. </span></li><li><span class="talkstart">19 June, Nancy, France: </span><span class="talktitle" lang="fr" xml:lang="fr">États des lieux du Web sémantique<span class="hide noprint">.</span></span><span class="talkdesc">Ivan Herman gives a keynote at <a href="http://ic2008.loria.fr/" lang="fr" xml:lang="fr">19èmes Journées Francophones d'Ingénierie des Connaissances (IC2008)</a>. </span></li><li><span class="talkstart">19 June, Baltimore, Maryland, USA: </span><span class="talktitle">How New Web Accessibility Standards Impact User Experience Design<span class="hide noprint">.</span></span><span class="talkdesc">Shawn Henry presents at <a href="http://www.usabilityprofessionals.org/conference/2008/">Usability Professionals' Association International Conference 2008</a>. </span></li><li><span class="talkstart">26 June, Frankfurt, Germany: </span><span class="talktitle">Mobile Internet - the Way Forward<span class="hide noprint">.</span></span><span class="talkdesc">Steve Bratt participates in a panel at <a href="http://www.amiando.com/ngmn-2008">2nd NGMN Industry Conference 2008</a>. </span></li><li class="noprint showuris">View <a href="http://www.w3.org/2004/08/W3CTalks?date=Recent+and+upcoming&amp;countryListing=yes&amp;submit=Submit">upcoming talks by country</a></li><li class="noprint showuris"><a href="/Talks/">More talks...</a></li></ul></div>
+
+<div id="item100" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />W3C Launches Group to Help Bridge the Digital Divide</h3><p><a href="/2008/MW4D/"><img class="newsImage" alt="Phone bikes" src="/2008/05/voiturette-sb.png" /></a><span class="date">2008-05-27:</span> As part of the growing set of W3C initiatives related to social development, W3C invites participation in the new <a href="/2008/MW4D/">Mobile Web for Development (MW4D) interest Group</a>, chartered to explore the potential of mobile technology to help bridge the digital divide. "We need to solve important challenges, such as lack of standards in end-user devices, network constraints, service cost, issues of literacy, and an understanding of the real information needs of rural communities," said Ken Banks, kiwanja.net, who Chairs the group. "To do so requires an multidisciplinary approach, a step we take through the creation of this new group." Read more in the <a href="/2008/05/mw4dig-pressrelease">press release</a>. This launch is part of <a href="/Mobile">W3C's Mobile Web Initiative (MWI)</a>, which aims to identify and resolve challenges and issues of accessing the Web when on the move. This work takes place under the auspices of the <a href="http://cordis.europa.eu/fp7/ict/">European Union's 7th Research Framework Programme (FP7)</a>, part of the <a href="http://digitalworld.ercim.org/">Digital World Forum</a> project.<span class="archive"> (Photo credit: Stéphane Boyera. <a title="W3C Launches Group to Help Bridge the Digital Divide" href="/News/2008#item100" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item99" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Last Call: XHTML Access Module</h3><p><span class="date">2008-05-26:</span> The <a href="/MarkUp/">XHTML 2 Working Group</a> has published the Last Call Working Draft of <a href="/TR/2008/WD-xhtml-access-20080526/">XHTML Access Module</a>. This document is intended to help make XHTML-family markup languages more effective at supporting the needs of the accessibility community. It does so by providing a generic mechanism for defining the relationship between document components and well-known accessibility taxonomies. Comments are welcome through 16 June. Learn more about the <a href="/MarkUp/Activity">HTML Activity</a>. <span class="archive"> (<a title="Last Call: XHTML Access Module" href="/News/2008#item99" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item98" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />W3C Invites Implementations of CSS Namespaces Module (Candidate Recommendation)</h3><p><span class="date">2008-05-23:</span> The <a href="/Style/CSS/members">Cascading Style Sheets (CSS) Working Group</a> has published the Candidate Recommendation of <a href="/TR/2008/CR-css3-namespace-20080523/">CSS Namespaces Module</a>. This CSS Namespaces module defines the syntax for using namespaces in CSS. It defines the @namespace rule for declaring the default namespace and binding namespaces to namespace prefixes, and it also defines a syntax that other specifications can adopt for using those prefixes in namespace-qualified names. Learn more about the <a href="/Style/">Style Activity</a>.<span class="archive"> (<a title="W3C Invites Implementations of CSS Namespaces Module (Candidate Recommendation)" href="/News/2008#item98" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item97" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Progress Events 1.0</h3><p><span class="date">2008-05-22:</span> The <a href="/2006/webapi/">Web API Working Group</a> has published a Working Draft of <a href="/TR/2008/WD-progress-events-20080521/">Progress Events 1.0</a>.This document describes event types that can be used for monitoring the progress of an operation. It is primarily intended for contexts such as data transfer operations specified by <a href="/TR/XMLHttpRequest">XMLHTTPRequest</a>, or <a href="/TR/MediaAccessEvents/">Media Access Events</a>. Learn more about the <a href="/2006/rwc/">Rich Web Client Activity</a>.<span class="archive"> (<a title="Progress Events 1.0" href="/News/2008#item97" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item96" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />XML Security Working Group to Take Next Steps on XML Signature, Encryption</h3><p><span class="date">2008-05-21:</span> W3C is pleased to announce the creation of the <a href="/2008/xmlsec/">XML Security Working Group</a>, whose mission is to evaluate and act on <a href="/2007/xmlsec/ws/report">recommendations</a> from the <a href="/2007/xmlsec/ws/agenda.html">September 2007 Workshop on XML Signature and XML Encryption</a> regarding next steps for XML Security specifications. The group's <a href="/2008/02/xmlsec-charter.html#deliverables">deliverables</a> include new work on XML Signature Syntax and Processing and XML Encryption Syntax and Processing, as well as maintenance of related specifications. Frederick Hirsch (Nokia) will Chair the group, with Thomas Roessler (W3C) as Team Contact. Learn more about the <a href="/Security/">W3C Security Activity</a>. <span class="archive"> (<a title="XML Security Working Group to Take Next Steps on XML Signature, Encryption" href="/News/2008#item96" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item94" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Last Call: Cascading Style Sheets (CSS) Snapshot 2007</h3><p><span class="date">2008-05-16:</span> The <a href="/Style/CSS/members">Cascading Style Sheets (CSS) Working Group</a> has published the Last Call Working Draft of <a href="/TR/2008/WD-css-beijing-20080516/">Cascading Style Sheets (CSS) Snapshot 2007</a>. This document collects together into one definition all the specifications that together form the current state of Cascading Style Sheets (CSS). The primary audience is CSS implementors, not CSS authors, as this definition includes modules by specification stability, not Web browser adoption rate. Comments are welcome through 09 June. Learn more about the <a href="/Style/">Style Activity</a>.<span class="archive"> (<a title="Last Call: Cascading Style Sheets (CSS) Snapshot 2007" href="/News/2008#item94" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item93" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />W3C Invites Implementations of XQuery and XPath Full Text 1.0 (Candidate Recommendation); Requirements and Use Cases Drafts Available</h3><p><span class="date">2008-05-16:</span> The W3C <a href="http://www.w3.org/XML/Query/">XML Query Working Group</a> and the W3C <a href="http://www.w3.org/Style/XSL/">XSL Working Group</a> jointly published today a Candidate Recommendation of <a href="/TR/2008/CR-xpath-full-text-10-20080516/">XQuery and XPath Full Text 1.0</a>. This document defines the syntax and formal semantics of XQuery and XPath Full Text 1.0 which is a language that extends XQuery 1.0 [XQuery 1.0: An XML Query Language] and XPath 2.0 [XML Path Language (XPath) 2.0] with full-text search capabilities. Implementors are encouraged to run the groups' <a href="http://dev.w3.org:/cvsweb/2007/xpath-full-text-10-test-suite/">test suite</a> and report their results. The Groups also published Working Drafts of <a href="/TR/2008/WD-xpath-full-text-10-requirements-20080516/">XQuery and XPath Full Text 1.0 Requirements</a> and <a href="/TR/2008/WD-xpath-full-text-10-use-cases-20080516/">Use Cases</a>. Learn more about the <a href="/XML/">XML Activity</a>.<span class="archive"> (<a title="W3C Invites Implementations of XQuery and XPath Full Text 1.0 (Candidate Recommendation); Requirements and Use Cases Drafts Available" href="/News/2008#item93" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item95" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />State Chart XML (SCXML) Working Draft Published</h3><p><span class="date">2008-05-16:</span> The <a href="/Voice/">Voice Browser Working Group</a> has published an updated Working Draft of <a href="/TR/2008/WD-scxml-20080516/">State Chart XML (SCXML): State Machine Notation for Control Abstraction</a>. <abbr title="State Chart eXtensible Markup Language">SCXML</abbr> is an execution environment based on <a href="http://www.uml.org/#UML1.5"><abbr title="Unified Modeling Language">UML</abbr></a> Harel State Tables and <a href="/TR/ccxml/"><abbr title="Call Control eXtensible Markup Language">CCXML</abbr></a>. The main differences from the previous draft are (1) the modularization of the language, (2) the introduction of profiles and (3) a revision of the algorithm for document interpretation; the document as a whole has changed significantly and the group welcomes review. Learn more about the <a href="/Voice/">Voice Browser Activity</a>.<span class="archive"> (<a title="State Chart XML (SCXML) Working Draft Published" href="/News/2008#item95" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item92" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />"Web Accessibility for Older Users: A Literature Review"; Comments Welcome on First Public Draft</h3><p><span class="date">2008-05-14:</span> The Web Accessibility Initiative (WAI) <a href="/WAI/EO/">Education and Outreach Working Group Working Group (EOWG)</a> has published <a href="/TR/2008/WD-wai-age-literature-20080514/">Web Accessibility for Older Users: A Literature Review</a> as a First Public Working Draft. The document includes reviews and analysis of guidelines and articles covering the requirements of people with Web accessibility needs related to ageing. This literature review will inform WAI efforts to promote accessibility solutions for older Web users and potentially to develop profiles or extensions to WAI guidelines. The literature review is a deliverable of the <a href="/WAI/WAI-AGE/">WAI-AGE Project</a> (Ageing Education and Harmonisation). See the <a href="http://lists.w3.org/Archives/Public/w3c-wai-ig/2008AprJun/0083.html">call for review and participation</a> for an introduction to the project and an invitation to contribute to the literature review and other WAI-AGE work; and about the <a href="/WAI/">Web Accessibility Initiative</a>.<span class="archive"> (<a title="Web Accessibility for Older Users: A Literature Review; Comments Welcome on First Public Draft" href="/News/2008#item92" rel="details">Permalink</a>) </span></p></div>
+
+<div id="item91" class="item"><h3><img alt="" width="17" height="11" src="/Icons/right" />Last Call: CURIE Syntax 1.0</h3><p><span class="date">2008-05-08:</span> The <a href="/MarkUp/">XHTML2 Working Group</a> has published the Last Call Working Draft of <a href="/TR/2008/WD-curie-20080506">CURIE Syntax 1.0</a>, which outlines a syntax for expressing URIs in a generic, abbreviated syntax ("Compact URI"). The specification targets language designers who need a mechanism to permit the use of extensible value collections. Any language designer considering the use of QNames in attribute values should consider instead using CURIEs, since CURIEs are designed for this purpose, while QNames are not. Comments are welcome through 10 June. Learn more about the <a href="/MarkUp/Activity">HTML Activity</a>.<span class="archive"> (<a title="Last Call: CURIE Syntax 1.0" href="/News/2008#item91" rel="details">Permalink</a>) </span></p></div>
+
+
+
+<h3 class="pastNews"><a href="/News/2008">Past News</a></h3>
+</div>
+
+<div class="navBlock">
+<h2 class="navhead"><a name="search" id="search">Search</a></h2>
+
+<p class="invisible"><a class="navlink" title="Skip search" href="#contents">Skip to Contents</a></p>
+
+<form method="get" action="http://www.google.com/custom" enctype="application/x-www-form-urlencoded">
+<div>
+<a class="navlink" href="http://www.google.com"><img src="/Icons/Logo_25wht.gif" width="75" height="32" alt="Google" /></a><br />
+<label for="inputField">Search W3C<br />
+<input type="text" size="15" id="inputField" name="q" accesskey="E" maxlength="255" /></label> <input type="submit" value="Go" id="goButton" name="sa" accesskey="G" /><br />
+<input type="hidden" name="cof" value="T:black;LW:72;ALC:#ff3300;L:http://www.w3.org/Icons/w3c_home;LC:#000099;LH:48;BGC:white;AH:left;VLC:#660066;GL:0;AWFID:0b9847e42caf283e;" />
+ <input type="hidden" id="searchW3C" name="sitesearch" checked="checked" value="www.w3.org" /><input type="hidden" name="domains" value="www.w3.org" />
+</div>
+</form>
+
+<p><a class="navlink" href="/Search/Mail/Public/">Search W3C Mailing
+Lists</a></p>
+
+<h2 class="navhead"><a name="contents" id="contents">Testimonials</a></h2>
+
+<div class="hpmt"><div class="hpmt-name">Fraunhofer Gesellschaft</div><div class="hpmt-logo"><a rel="nofollow" href="http://www.fraunhofer.de/"><img alt="Fraunhofer Gesellschaft" src="http://www.w3.org/Consortium/Member/Testimonial/Logo/119" /></a></div><p class="hpmt-testimonial">The Fraunhofer-Gesellschaft undertakes applied contract research in all fields of engineering sciences. Fraunhofer works with W3C to contribute to the development of Web technologies which are the base of many of our research activities. Fraunhofer hosts the W3C Office in Germany and Austria. <a class="hpmt-more" href="http://www.w3.org/Consortium/Member/Testimonial/List">(Member testimonials)</a></p></div>
+
+<h2 class="navhead">Members</h2>
+
+<ul>
+<li><a href="/Member/" class="navlink">Member Home Page</a></li>
+
+<li><a href="/Submission/" class="navlink">Member Submissions</a></li>
+
+<li><a href="/Consortium/Member/List" class="navlink">Current
+Members</a></li>
+
+<li><a href="/Consortium/meetings" class="navlink">Meetings</a></li>
+
+<li><a href="/Consortium/Recruitment/Fellows" class="navlink">Fellows</a> (<a href="/Consortium/Recruitment/Fellows#openings">New Openings</a>)</li>
+</ul>
+
+<h2 class="navhead">Get Involved</h2>
+
+<ul>
+<li><a href="/Consortium/membership-benefits" class="navlink">W3C
+Membership Benefits</a></li>
+
+<li><a href="/Consortium/membership#bizcase" class="navlink">Reasons to
+Join W3C</a></li>
+
+<li><a href="/Mail/" class="navlink">Mailing Lists</a></li>
+
+<li><a href="http://lists.w3.org/Archives/Public/public-new-work/latest">Potential
+New Work</a></li>
+
+<li><a href="/Consortium/Translation/" class="navlink">Translations</a></li>
+
+<li><a href="/2003/08/Workshops/" class="navlink">Workshops</a></li>
+
+<li><a href="/2001/11/StdLiaison" class="navlink">Liaisons</a></li>
+
+<li><a href="/Status" class="navlink">Open Source Software</a></li>
+
+<li><a href="/QA/" class="navlink">Q&amp;A Blog</a></li>
+
+<li><a href="/Consortium/Recruitment/" class="navlink">Employment</a></li>
+
+<li><span class="navText">More ways to</span> <a href="/Consortium/org#public" class="navlink">participate</a></li>
+</ul>
+
+<h2 class="navhead">Introduction</h2>
+
+<ul>
+<li><a href="/Consortium/" class="navlink">About W3C</a></li>
+
+<li><a href="/Consortium/faq" class="navlink">Frequently Asked
+Questions (FAQ)</a></li>
+
+<li><a href="/2003/glossary/" class="navlink">Glossary</a></li>
+
+<li><a href="/Consortium/Process/" class="navlink">Process
+Document</a></li>
+
+<li><a href="/2002/03/tutorials" class="navlink">Tutorials</a></li>
+
+<li><a href="/2002/03/new-to-w3c" class="navlink">More...</a></li>
+</ul>
+
+<h2 class="navhead">W3C Team</h2>
+
+<ul>
+<li><a href="/People/" class="navlink">People</a></li>
+
+<li><a href="/TeamSubmission/" class="navlink">Team
+Submissions</a></li>
+</ul>
+
+<h2 class="navhead">Presentations</h2>
+
+<ul>
+<li><a href="/Talks/" class="navlink">Public Presentations</a></li>
+</ul>
+
+<h2 class="navhead">News Room</h2>
+
+<ul>
+<li><a href="/News/" class="navlink">W3C News Archive</a> <span class="navText">(</span><a href="/2000/08/w3c-synd/home.rss" class="navlink">RSS</a><span class="navText">)</span></li>
+
+<li><a href="/News/Public/" class="navlink">Weekly Public Newsletter</a></li>
+
+<li><a href="/Press/" class="navlink">Press Releases</a></li>
+
+<li><a href="/Press/#rss" class="navlink">Multilingual Press Release
+RSS</a></li>
+
+<li><a href="/Press/Articles" class="navlink">W3C in the Press</a></li>
+</ul>
+
+<h2 class="navhead"><a name="Offices" id="Offices">World
+Offices</a></h2>
+
+<p class="navPara">The <a href="/Consortium/Offices/" class="navlink">W3C Offices</a>, part of the <a href="/2007/IntlRel.html">W3C
+International Relations team</a> translate many W3C home page news
+items. W3C Offices are located in these parts of the world:</p>
+
+<ul>
+<li><a href="http://www.w3c.org.au/" class="navlink" title="Australia">Australia</a></li>
+
+<li><a href="http://www.w3c.nl/index.shtml.nl" class="navlink" hreflang="nl" title="Benelux"><span xml:lang="nl" lang="nl">Benelux</span></a>/<a href="http://www.w3c.nl/index.shtml.fr" class="navlink" title="Benelux" hreflang="fr"><span xml:lang="fr" lang="fr">Bénélux</span></a></li>
+
+<li><a href="http://www.w3c.br/" class="navlink" title="Brazil" hreflang="pt-br"><span xml:lang="pt-br" lang="pt-br">Brasil</span>
+(Brazil)</a></li>
+
+<li><a href="http://www.chinaw3c.org/" class="navlink" title="China" hreflang="zh-hans"><span xml:lang="zh-hans" lang="zh-hans">中国</span>
+(China)</a></li>
+
+<li><a href="http://www.w3c.tut.fi/" class="navlink" title="Finland" hreflang="fi"><span xml:lang="fi" lang="fi">Suomi</span>
+(Finland)</a></li>
+
+<li><a href="http://www.w3c.de/" class="navlink" title="German and Austria" hreflang="de"><span xml:lang="de" lang="de">Deutschland und Österreich</span> (Germany and Austria)</a></li>
+
+<li><a href="http://www.w3c.gr/" class="navlink" title="Greece" hreflang="el"><span xml:lang="el" lang="el">Ελλάδα</span>
+(Greece)</a></li>
+
+<li><a href="http://www.w3c.hu/" class="navlink" title="Hungary" hreflang="hu"><span xml:lang="hu" lang="hu">Magyarország</span>
+(Hungary)</a></li>
+
+<li><a href="http://www.w3cindia.in/" class="navlink" title="India" hreflang="en"><span xml:lang="hi" lang="hi">भारत</span>
+(India)</a></li>
+
+<li><a href="http://www.w3c.org.il/" class="navlink" title="Israel" hreflang="he"><span xml:lang="he" lang="he">ישראל</span>
+(Israel)</a></li>
+
+<li><a href="http://www.w3c.it/" class="navlink" title="Italy" hreflang="it"><span xml:lang="it" lang="it">Italia</span>
+(Italy)</a></li>
+
+<li><a href="http://www.w3c.or.kr/" class="navlink" title="Korea" hreflang="ko"><span xml:lang="ko" lang="ko">한국</span> (Korea)</a></li>
+
+<li><a href="http://www.w3c.org.ma/" class="navlink" title="Morocco" hreflang="ar"><span xml:lang="ar" lang="ar">المغرب</span>
+(Morocco)</a></li>
+
+<li><a href="http://www.w3c.org.za/" class="navlink" title="Southern Africa" hreflang="en">Southern Africa</a></li>
+
+<li><a href="http://www.w3c.es/" class="navlink" title="Spain" hreflang="es"><span xml:lang="es" lang="es">España</span>
+(Spain)</a></li>
+
+<li><a href="http://www.w3c.se" class="navlink" title="Sweden" hreflang="sv"><span xml:lang="sv" lang="sv">Sverige</span>
+(Sweden)</a></li>
+
+<li><a href="http://www.w3c.rl.ac.uk/" class="navlink" title="UK and Ireland" hreflang="en-uk">United Kingdom and Ireland</a></li>
+</ul>
+
+<h2 class="navhead"><a name="systems" id="systems">Systems</a></h2>
+
+<ul>
+<li><a href="/Help/Account/" class="navlink">Get Password</a></li>
+
+<li><a href="/2003/08/system-status" class="navlink">System
+Status</a></li>
+</ul>
+</div>
+<hr class="hide" />
+
+<p class="small">W3C would like to thank the <a name="donors" id="donors" href="/Consortium/sup">Supporters</a> who have contributed
+financially or through a donation of goods to W3C.</p>
+
+<p class="small"><a name="footnotes" id="footnotes">Read</a> <a href="/2002/11/homepage">about the layout</a> and <a href="http://lists.w3.org/Archives/Public/site-comments/">send comments</a>
+about this page. <a href="/2000/08/w3c-synd/home.rss">Syndicate</a>
+this page with <a href="http://purl.org/rss/1.0/">RSS 1.0</a>, an
+<a href="/RDF/">RDF</a> vocabulary used for <a href="/2000/08/w3c-synd/#">site summaries</a>. </p>
+
+<address class="small">
+<a href="/Help/Webmaster">Webmaster</a> · Last modified:
+ $Date: 2008/06/05 17:06:19 $
+ <span class="whiteout">|</span><br />
+<a href="http://validator.w3.org/check?uri=referer"><img src="/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a> <span class="whiteout">|</span> <a href="http://jigsaw.w3.org/css-validator/"><img src="/Icons/valid-css" alt="Valid CSS!" height="31" width="88" /></a> <span class="whiteout">|</span> <a href="/WAI/WCAG1AA-Conformance" title="Explanation of Level Double-A Conformance"><img class="conform" height="31" width="88" src="/WAI/wcag1AA" alt="Level Double-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0" />
+</a> <span class="whiteout">|</span>
+</address>
+
+<p class="copyright"><a rel="Copyright" href="/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 1994-2007
+<a href="/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
+<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
+<a href="/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
+<a href="/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>,
+<a rel="Copyright" href="/Consortium/Legal/copyright-documents">document use</a> and <a rel="Copyright" href="/Consortium/Legal/copyright-software">software
+licensing</a> rules apply. Your interactions with this site are in
+accordance with our <a href="/Consortium/Legal/privacy-statement#Public">public</a> and <a href="/Consortium/Legal/privacy-statement#Members">Member</a> privacy
+statements.</p>
+</body>
+</html>
diff --git a/examples/xml/htmlinfo/youtube_com.html b/examples/xml/htmlinfo/youtube_com.html
new file mode 100644
index 0000000000..1de65a3aa5
--- /dev/null
+++ b/examples/xml/htmlinfo/youtube_com.html
@@ -0,0 +1,1585 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
+
+
+ <html lang="en">
+
+<!-- machid: 519 -->
+<head>
+
+ <title>YouTube - Broadcast Yourself.</title>
+
+ <link rel="stylesheet" href="http://s.ytimg.com/yt/css/base_all-vfl42327.css" type="text/css">
+
+ <link rel="search" type="application/opensearchdescription+xml" href="/opensearch?locale=en_US" title="YouTube Video Search">
+ <link rel="icon" href="http://s.ytimg.com/yt/favicon-vfl1123.ico" type="image/x-icon">
+ <link rel="shortcut icon" href="http://s.ytimg.com/yt/favicon-vfl1123.ico" type="image/x-icon">
+
+
+ <meta name="description" content="Share your videos with friends and family">
+ <meta name="keywords" content="video,sharing,camera phone,video phone,free">
+
+ <link rel="alternate" type="application/rss+xml" title="YouTube - [RSS]" href="/rssls">
+
+ <link rel="alternate" media="handheld" href="http://m.youtube.com/index?desktop_uri=%2F&">
+
+ <script type="text/javascript">
+ window.google={kHL:"en"};
+ </script>
+
+ <script type="text/javascript" src="http://s.ytimg.com/yt/js/base_all_with_bidi-vfl42302.js"></script>
+
+ <script type="text/javascript">
+
+ function _hbLink (a,b) { return false; }
+ function urchinTracker (a,b) { }
+
+
+ var gXSRF_token = '';
+ var gXSRF_field_name = '';
+ var gXSRF_ql_pair = '';
+
+ gXSRF_token = 'fZg-xPKpfj11aUrz_5__moOGiAp8MTIxMjg1OTQ4OA==';
+ gXSRF_field_name = 'session_token';
+ onLoadFunctionList.push(populate_session_token);
+
+ gXSRF_ql_pair = 'session_token=kVjpl8qnfp7RPuqnTrIu6Q8BT5d8MA==';
+
+
+ var gQuickListTooltipText = 'Add Video to QuickList';
+ var gPartnerVideoText = 'Partner Video';
+ var gGoogleSuggest = true;
+ var gPixelGif = 'http://s.ytimg.com/yt/img/pixel-vfl73.gif';
+
+ var gInQuickListText = 'in <a href="/watch_queue?all">QuickList</a>';
+ var gIsResultsPage = false;
+ </script>
+
+
+
+<script type="text/javascript">
+
+function swapVideoList(linkObj)
+{
+ var linkId = linkObj.id;
+ var queryData = '';
+ var newDivId = '';
+ var headlineObj = document.getElementById('hpVideoListHead');
+ var moreLinkObj = document.getElementById('homepage-featured-more-top');
+ var bottomMoreLinkObj = document.getElementById('homepage-featured-more-bottom');
+
+ if (linkId == 'hpMostViewedLink') {
+ queryData = 'videoListType=mostViewed';
+ newDivId = 'hpMostViewed';
+ headlineObj.innerHTML = "Most Viewed Videos";
+ moreLinkObj.innerHTML = "<a href=\"/browse?s=mp\">See More Most Viewed Videos</a>";
+ bottomMoreLinkObj.innerHTML = "<a href=\"/browse?s=mp\">See More Most Viewed Videos</a>";
+ }
+ else if (linkId == 'hpMostDiscussedLink') {
+ queryData = 'videoListType=mostDiscussed';
+ newDivId = 'hpMostDiscussed';
+ headlineObj.innerHTML = "Most Discussed Videos";
+ moreLinkObj.innerHTML = "<a href=\"/browse?s=md\">See More Most Discussed Videos</a>";
+ bottomMoreLinkObj.innerHTML = "<a href=\"/browse?s=md\">See More Most Discussed Videos</a>";
+ }
+ else if (linkId == 'hpTopFavoritesLink') {
+ queryData = 'videoListType=topFavorites';
+ newDivId = 'hpTopFavorites';
+ headlineObj.innerHTML = "Top Favorites";
+ moreLinkObj.innerHTML = "<a href=\"/browse?s=mf\">See More Top Favorites</a>";
+ bottomMoreLinkObj.innerHTML = "<a href=\"/browse?s=mf\">See More Top Favorites</a>";
+ }
+ else if (linkId == 'hpFeaturedLink') {
+ newDivId = 'hpFeatured';
+ headlineObj.innerHTML = "Featured Videos";
+ moreLinkObj.innerHTML = "<a href=\"/browse?s=rf\">See More Featured Videos</a>";
+ bottomMoreLinkObj.innerHTML = "<a href=\"/browse?s=rf\">See More Featured Videos</a>";
+ }
+ self.containerDiv = 'homepage-video-list'
+ self.fillDiv = fillDiv
+ self.linkId = linkId
+ self.newDivId = newDivId
+ addClass(_gel(newDivId + 'Link'), 'hilite');
+ if (newDivId != 'hpMostViewed') {
+ removeClass(_gel('hpMostViewedLink'), 'hilite');
+ }
+ if (newDivId != 'hpMostDiscussed') {
+ removeClass(_gel('hpMostDiscussedLink'), 'hilite');
+ }
+ if (newDivId != 'hpTopFavorites') {
+ removeClass(_gel('hpTopFavoritesLink'), 'hilite');
+ }
+ if (newDivId != 'hpFeatured') {
+ removeClass(_gel('hpFeaturedLink'), 'hilite');
+ }
+ if (document.getElementById(newDivId))
+ {
+ document.getElementById(newDivId).style.display = 'block';
+ if (newDivId != 'hpMostViewed' && document.getElementById('hpMostViewed')) document.getElementById('hpMostViewed').style.display = 'none';
+ if (newDivId != 'hpMostDiscussed' && document.getElementById('hpMostDiscussed')) document.getElementById('hpMostDiscussed').style.display = 'none';
+ if (newDivId != 'hpTopFavorites' && document.getElementById('hpTopFavorites')) document.getElementById('hpTopFavorites').style.display = 'none';
+ if (newDivId != 'hpFeatured' && document.getElementById('hpFeatured')) document.getElementById('hpFeatured').style.display = 'none';
+ }
+ else if (queryData != '') {
+ postUrlXMLResponse('/ajax_video_list',queryData,self.fillDiv);
+ }
+}
+function fillDiv(req)
+{
+ if (document.getElementById('hpMostViewed')) document.getElementById('hpMostViewed').style.display = 'none';
+ if (document.getElementById('hpMostDiscussed')) document.getElementById('hpMostDiscussed').style.display = 'none';
+ if (document.getElementById('hpTopFavorites')) document.getElementById('hpTopFavorites').style.display = 'none';
+ if (document.getElementById('hpFeatured')) document.getElementById('hpFeatured').style.display = 'none';
+ var newContent = getNodeValue(req.responseXML, "html_content");
+ var newdiv = document.createElement('div');
+ newdiv.setAttribute("id",self.newDivId);
+ newdiv.innerHTML = newContent;
+ var container = document.getElementById(self.containerDiv);
+ container.appendChild(newdiv);
+ addQLIcons(container);
+}
+
+function hide_active_sharing() {
+ hideDiv("active_sharing_div");
+}
+</script>
+
+</head>
+
+
+<body onload="performOnLoadFunctions();" class="en_US is-english">
+
+<div id="baseDiv" class="date-20080606">
+
+ <div id="masthead">
+ <a href="/" class="logo"><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" width="132" height="63" border="0" alt=""/></a>
+ <div class="user-info">
+
+ <div id="loginBoxZ">
+ <div class="contentBox">
+ <div>
+ <div id="loginBoxZ-signup">
+ <a href="/signup">Sign Up</a>
+ | <a href="http://help.youtube.com/support/youtube/bin/topic.py?topic=10546&amp;hl=en_US">Help</a>
+ </div>
+ <div id="loginBoxZ-login">
+ Login
+ </div>
+ <div class="clear"></div>
+ </div>
+
+ <form method="post" name="loginForm" id="loginFormZ" action="/signup">
+ <input type="hidden" name="next" value="/" id="loginNextZ"/>
+ <input type="hidden" name="current_form" value="loginForm" />
+ <input type="hidden" name="action_login" value="1">
+ <div id="loginBoxZ-container">
+ <div id="loginBoxZ-labels" class="floatL">
+ <label for="loginUserZ" class="nowrap">Username:</label>
+ <label for="loginPassZ" class="nowrap">Password:</label>
+ </div>
+ <div class="floatL">
+ <input id="loginUserZ" class="loginBoxZ-input" type="text" size="16" name="username" value=""><br/>
+ <input id="loginPassZ" class="loginBoxZ-input" type="password" size="16" name="password"><br/>
+ <input type="submit" class="smallText" value="Login">
+ </div>
+ <div class="clearL"></div>
+ </div>
+ </form>
+ <div id="loginBoxZ-forgot">
+ <a href="/forgot_username?next=/">Forgot Username</a>
+ | <wbr><nobr><a href="/forgot?next=/">Forgot Password</a></nobr>
+ </div>
+ <div id="loginBoxZ-gaia">
+ <a href="https://www.google.com/accounts/ServiceLogin?service=youtube&amp;hl=en_US&amp;continue=http%3A//www.youtube.com/signup%3Fhl%3Den_US&amp;passive=true">Login with your Google account</a>&nbsp;
+ <a href="#" onClick="window.open('/t/help_gaia','login_help','width=580,height=480,resizable=yes,scrollbars=yes,status=0').focus();" rel="nofollow"><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" border="0" class="alignMid gaiaHelpBtn" alt=""></a>
+ </div>
+ </div>
+ </div>
+
+ <div id="localePickerBox">
+ <div id="flagDiv">
+ <script type="text/javascript">
+ var gLocales = [
+ ['ru_RU','&#x420;&#x43E;&#x441;&#x441;&#x438;&#x44F;'] , ['zh_TW','&#x53F0;&#x7063;'] , ['ja_JP','&#x65E5;&#x672C;'] , ['zh_HK','&#x9999;&#x6E2F;'] , ['ko_KR','&#xD55C;&#xAD6D;'] , ['en_AU','Australia'] , ['pt_BR','Brasil'] , ['en_CA','Canada'] , ['de_DE','Deutschland'] , ['es_ES','Espa&#xF1;a'] , ['fr_FR','France'] , ['en_US','Global'] , ['en_IN','India'] , ['en_IE','Ireland'] , ['it_IT','Italia'] , ['es_MX','M&#xE9;xico'] , ['nl_NL','Nederland'] , ['en_NZ','New Zealand'] , ['pl_PL','Polska'] , ['en_GB','United Kingdom']
+ ];
+ </script>
+ <div id="flagDivInner">
+ </div>
+
+ <div class="alignR smallText"><a href="#" onclick="closeLocalePicker(); return false;">Close</a></div>
+ </div>
+ </div>
+
+
+
+
+
+
+ <div id="util-links" class="normal-utility-links">
+
+ <span class="util-item first"><b><a href="/signup" onclick="_hbLink('SignUp','UtilityLinks');">Sign Up</a></b></span>
+ <span class="util-item"><a href="/watch_queue?all">QuickList</a> (<span id="quicklist-utility">0</span>)</span>
+ <span class="util-item"><a href="http://help.youtube.com/support/youtube/bin/static.py?page=start.cs&amp;hl=en_US">Help</a></span>
+ <span class="util-item"><a href="#" class="loginBoxZ eLink" onclick="return openLoginBox(event);">Log In</a></span>
+ <span class="util-item"><a href="#" class="localePickerLink eLink" onclick="loadFlagImgs();toggleDisplay('localePickerBox');return false;">Site:</a></span>
+ <span class="util-item first">&nbsp;<a href="#" class="localePickerLink" onclick="loadFlagImgs();toggleDisplay('localePickerBox');return false;"><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="currentFlag globalFlag" alt="Site:"></a></span>
+ </div>
+
+ <form name="logoutForm" method="post" target="_top" action="/index">
+ <input type="hidden" name="action_logout" value="1">
+ </form>
+
+
+ </div>
+ <div class="nav">
+ <div class="nav-item first selected" id="nav-item-home">
+ <span class="leftcap"></span>
+ <a class="content" href="/">Home</a>
+ <span class="rightcap"></span>
+ </div>
+ <div class="nav-item" id="nav-item-videos">
+ <div class="nav-tab">
+ <span class="leftcap"></span>
+ <a class="content" href="/browse?s=mp">Videos</a>
+ <span class="rightcap"></span>
+ </div>
+ </div>
+ <div class="nav-item" id="nav-item-channels">
+ <div class="nav-tab">
+ <span class="leftcap"></span>
+ <a class="content" href="/members">Channels</a>
+ <span class="rightcap"></span>
+ </div>
+ </div>
+ <div class="nav-item" id="nav-item-community">
+ <div class="nav-tab">
+ <span class="leftcap"></span>
+ <a class="content" href="/community">Community</a>
+ <span class="rightcap"></span>
+ </div>
+ </div>
+ </div>
+
+ <form autocomplete="off" action="/results" method="get" name="searchForm" onsubmit="return submitRegularSearchRequest()">
+
+ <div class="bar">
+ <span class="leftcap"></span>
+ <div class="search-bar">
+ <a href="/my_videos_upload" id="upload-button" class="action-button">
+ <span class="action-button-leftcap"></span>
+ <span class="action-button-text">Upload</span>
+ <span class="action-button-rightcap"></span>
+ </a>
+ <div id="search-form">
+ <input id="search-term" name="search_query" type="text" tabindex="1" onkeyup="goog.i18n.bidi.setDirAttribute(event,this)" value="" maxlength="128" />
+ <select class="search-type" name="search_type">
+ <option value="">Videos</option>
+ <option value="search_users" >Channels</option>
+ </select>
+ <input id="search-button" type="submit" value="Search" />
+ </div>
+ <div class="search-settings-link">
+ <a href="#" class="eLink" onClick="return toggleAdvSearch('', '', '', '', '', '')">
+ advanced
+ </a></div>
+ </div>
+ <span class="rightcap"></span>
+ </div>
+
+ </form>
+
+ <div id="search-advanced-form" class="hid">
+ <div class="search-setting-inner alignC">Loading...</div>
+ </div>
+
+ <div class="clear"></div>
+ </div>
+ <div id="search-settings-clr" class="hid"></div>
+
+
+
+
+
+
+<div id="homepage-main-content">
+ <div>
+ <div id="active_sharing_div" name="active_sharing_div" style="display:block"></div>
+ <script type="text/javascript">
+ // <![CDATA[
+ var fo = new SWFObject("active_sharing.swf", "active_sharing", "550", "115", 7, "#FFFFFF");
+ var showstr = "Videos being watched right now...";
+ fo.addParam('wmode', 'opaque');
+ fo.addVariable("t", showstr);
+ fo.write("active_sharing_div");
+ // ]]>
+ </script>
+</div>
+
+ <div class="homepage-content-block" style="margin-left:18px; border:0px #CCC solid;">
+ <div class="homepage-block-heading homepage-block-heading-gray">Promoted Videos</div>
+ <div>
+ <div class="homepage-sponsored-video marB0">
+ <div class="videoIconWrapperOuter">
+ <div class="videoIconWrapperInner">
+ <div class="vstill"><a href="/cthru?key=YSqt3w6VDhuNgxUzVZsryt0JX30ll7tCIrBT--_pvAtRC3KmvsBYFaUNR1qT0d0BnBJYjHz_G7LIr21ufG7W6gJL7zPdHNbcmuIxaafL1yry8cdcqeEOTitWLXkpm2q2QnTAlp4chC1jus7JLVCnCdacl0xUeDk4Vk8e6q9htmGbDZPN9QMnHsrX2RZnvDMx-3Im14C3GKi4jI8ee-jnOQ==" name="&lid=DV+-+BasiaBulatInTheNight+-+beggars&lpos=hp-s0"><img src="http://i.ytimg.com/vi/CebHAvPHyyU/default.jpg" class="vimg120"></a></div>
+ </div>
+ </div>
+
+ <div class="vtitle smallText">
+ <a href="/cthru?key=YSqt3w6VDhuNgxUzVZsryt0JX30ll7tCIrBT--_pvAtRC3KmvsBYFaUNR1qT0d0BnBJYjHz_G7LIr21ufG7W6gJL7zPdHNbcmuIxaafL1yry8cdcqeEOTitWLXkpm2q2QnTAlp4chC1jus7JLVCnCdacl0xUeDk4Vk8e6q9htmGbDZPN9QMnHsrX2RZnvDMx-3Im14C3GKi4jI8ee-jnOQ==" name="&lid=DV+-+BasiaBulatInTheNight+-+beggars&lpos=hp-s0">Basia Bulat - In Th...</a>
+ </div>
+ <div class="vfacets" style="margin-bottom: 0px;">
+ <a href="/user/beggars" class="dg">beggars</a>
+ </div>
+ </div>
+ <div class="homepage-sponsored-video marB0">
+ <div class="videoIconWrapperOuter">
+ <div class="videoIconWrapperInner">
+ <div class="vstill"><a href="/cthru?key=FIUXMxdvOKhDw2_wpR7bE9L-XUsHMZBHRpS_s21B0Kq0RTWlGXSqQ8bjw6tBQOUczUtO8b6_mktukdd5ChseYAl10dE5JQrlpiOQE6HNMOAsszaA0M9qhzFnOkWPrkFGMDW5vvaAOkIwas6ksi4e_R8wkiIhlNYPDiqi2f4LpVzB2jpe0LobjIEF9czWjFx9ymrPg8wx2x6w00jF-BzRfQ==" name="&lid=DV+-+Perfection+-+corporalcadet&lpos=hp-s1"><img src="http://i.ytimg.com/vi/Np4bhsmr3iE/default.jpg" class="vimg120"></a></div>
+ </div>
+ </div>
+
+ <div class="vtitle smallText">
+ <a href="/cthru?key=FIUXMxdvOKhDw2_wpR7bE9L-XUsHMZBHRpS_s21B0Kq0RTWlGXSqQ8bjw6tBQOUczUtO8b6_mktukdd5ChseYAl10dE5JQrlpiOQE6HNMOAsszaA0M9qhzFnOkWPrkFGMDW5vvaAOkIwas6ksi4e_R8wkiIhlNYPDiqi2f4LpVzB2jpe0LobjIEF9czWjFx9ymrPg8wx2x6w00jF-BzRfQ==" name="&lid=DV+-+Perfection+-+corporalcadet&lpos=hp-s1">Perfection</a>
+ </div>
+ <div class="vfacets" style="margin-bottom: 0px;">
+ <a href="/user/corporalcadet" class="dg">corporalcadet</a>
+ </div>
+ </div>
+ <div class="homepage-sponsored-video marB0">
+ <div class="videoIconWrapperOuter">
+ <div class="videoIconWrapperInner">
+ <div class="vstill"><a href="/cthru?key=1W2J508g9g7Bjsvodsvq3GHZo25JkqX7Js5JSHnyP1yZYB96KDh2LTC2pCKjeHc7LEiTUU4uhuwsrTzZfns_IR2dsA7leCUYMtvgq3noBHy-G0jTHmgiQtFUVTDU3jT2EkS39J6Ur2qxtHwAmybMcU83hK1guqpPdryKOfcbHovo-Kbwglzbbl28LrK1iNdz5E6NZ5CZCVZrYxldbWyjEA==" name="&lid=DV+-+WhatmatterstoyoumeVFS+-+Jr0canest&lpos=hp-s2"><img src="http://i.ytimg.com/vi/KExoP97KUnY/default.jpg" class="vimg120"></a></div>
+ </div>
+ </div>
+
+ <div class="vtitle smallText">
+ <a href="/cthru?key=1W2J508g9g7Bjsvodsvq3GHZo25JkqX7Js5JSHnyP1yZYB96KDh2LTC2pCKjeHc7LEiTUU4uhuwsrTzZfns_IR2dsA7leCUYMtvgq3noBHy-G0jTHmgiQtFUVTDU3jT2EkS39J6Ur2qxtHwAmybMcU83hK1guqpPdryKOfcbHovo-Kbwglzbbl28LrK1iNdz5E6NZ5CZCVZrYxldbWyjEA==" name="&lid=DV+-+WhatmatterstoyoumeVFS+-+Jr0canest&lpos=hp-s2">What matters to you...</a>
+ </div>
+ <div class="vfacets" style="margin-bottom: 0px;">
+ <a href="/user/Jr0canest" class="dg">Jr0canest</a>
+ </div>
+ </div>
+ <div class="homepage-sponsored-video marB0">
+ <div class="videoIconWrapperOuter">
+ <div class="videoIconWrapperInner">
+ <div class="vstill"><a href="/cthru?key=idL1slcMKbuzX2MFZaS-nifq5PWrCKLUZMXEPqCthRVET6PQSkxlmKQVMNmQvlYpQlFISkRprfO113rH-ER0ytYh0zSMWI4XbaO74zcrIZiSpB3oISku9zIGUwS5WI03Y0ZiHbGAC9GIYziEcRcgzcEYuizlUwNvTWDgNSvrCJHcyPYokMUjLjcwqD2wEEAe7jfIfcJRNl3sW7ODuiN_MA==" name="&lid=DV+-+LIfeisaMasquerade+-+bananaruthy&lpos=hp-s3"><img src="http://i.ytimg.com/vi/l9gjk5hHiGM/default.jpg" class="vimg120"></a></div>
+ </div>
+ </div>
+
+ <div class="vtitle smallText">
+ <a href="/cthru?key=idL1slcMKbuzX2MFZaS-nifq5PWrCKLUZMXEPqCthRVET6PQSkxlmKQVMNmQvlYpQlFISkRprfO113rH-ER0ytYh0zSMWI4XbaO74zcrIZiSpB3oISku9zIGUwS5WI03Y0ZiHbGAC9GIYziEcRcgzcEYuizlUwNvTWDgNSvrCJHcyPYokMUjLjcwqD2wEEAe7jfIfcJRNl3sW7ODuiN_MA==" name="&lid=DV+-+LIfeisaMasquerade+-+bananaruthy&lpos=hp-s3">LIfe is a Masquerade.</a>
+ </div>
+ <div class="vfacets" style="margin-bottom: 0px;">
+ <a href="/user/bananaruthy" class="dg">bananaruthy</a>
+ </div>
+ </div>
+ <div class="clearL" style="height: 1px;"></div>
+ </div>
+ </div>
+
+
+ <div id="homepage-featured-heading">
+ <div id="homepage-featured-more-top"><a id="hpVideoListMoreLink" href="/browse?s=rf">See More Featured Videos</a></div>
+ <h1 id="hpVideoListHead">Featured Videos</h1>
+ </div>
+
+ <div id="homepage-featured-tabs">
+ <a href="#" id="hpTopFavoritesLink" name="&lid=hpTopFavoritesTab&lpos=hpTabs" onclick="swapVideoList(this); return false;">Top Favorites</a>
+ <a href="#" id="hpMostDiscussedLink" name="&lid=hpMostDiscussedTab&lpos=hpTabs" onclick="swapVideoList(this); return false;">Most Discussed</a>
+ <a href="#" id="hpMostViewedLink" name="&lid=hpMostViewedTab&lpos=hpTabs" onclick="swapVideoList(this); return false;">Most Viewed</a>
+ <a href="#" id="hpFeaturedLink" name="&lid=hpFeaturedTab&lpos=hpTabs" onclick="swapVideoList(this); return false;" class="first hilite">Featured</a>
+ <div class="clear"></div>
+ </div>
+
+
+
+ <div id="homepage-video-list" class="browseListView">
+ <div id="hpFeatured">
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=uu-NTSZ27b0"><img src="http://i.ytimg.com/vi/uu-NTSZ27b0/default.jpg" class="vimg120" title="Caribbean PVC Marimba Children's Orchestra" qliconalt="uu-NTSZ27b0" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=uu-NTSZ27b0" title="Caribbean PVC Marimba Children's Orchestra" onclick="_hbLink('CaribbeanPVCMarimbaChildrensOrchestra','VidVert');">Caribbean PVC Marimba Children's...</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=uu-NTSZ27b0" title="Caribbean PVC Marimba Children's Orchestra" onclick="_hbLink('CaribbeanPVCMarimbaChildrensOrchestra','VidVert');">Caribbean PVC Marimba Children's Orchestra</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescuuNTSZ27b0">
+ Michael Greiner who is a neighbor and good friend of mine asked me to upload several Marim
+ </span>
+
+ <span id="RemainvidDescuuNTSZ27b0" style="display: none">Michael Greiner who is a neighbor and good friend of mine asked me to upload several Marimba videos for him (that's him on the left in the middle row). He currently teaches the music program at Aveson Charter School http://aveson.org/ and constructs musical instruments in classes with students' participation.<br/><br/>Michael Greiner created this set of plastic pipe marimbas. On this clip are three generations of prototypes designed to be low cost for use by childrens' programming. The top one bass version costs around $200 in materials. The mallets are home made using foam flip-flops mounted to sticks. Filmed at Norma Coombs primary school in Altadena CA in 2007.<br/><br/>*** Edited to Add ****<br/>Wow, it looks like this video's hit YouTube's front page. Thank you for all the wonderfully kind and supportive comments!</span>
+ <span id="MorevidDescuuNTSZ27b0" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescuuNTSZ27b0'); hideDiv('MorevidDescuuNTSZ27b0'); hideDiv('BeginvidDescuuNTSZ27b0'); showDiv('LessvidDescuuNTSZ27b0'); return false;">more</a>)</span>
+ <span id="LessvidDescuuNTSZ27b0" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescuuNTSZ27b0'); hideDiv('LessvidDescuuNTSZ27b0'); showDiv('BeginvidDescuuNTSZ27b0'); showDiv('MorevidDescuuNTSZ27b0'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/PlayHanghang">PlayHanghang</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 3,853<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-5.0" alt="4.84814814815" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">01:46</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=24">Entertainment</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=CFJRn7akXeQ"><img src="http://i.ytimg.com/vi/CFJRn7akXeQ/default.jpg" class="vimg120" title="&quot;Sharp Teeth&quot; Excerpt #1" qliconalt="CFJRn7akXeQ" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=CFJRn7akXeQ" title="&quot;Sharp Teeth&quot; Excerpt #1" onclick="_hbLink('SharpTeethExcerpt1','VidVert');">&quot;Sharp Teeth&quot; Excerpt #1</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=CFJRn7akXeQ" title="&quot;Sharp Teeth&quot; Excerpt #1" onclick="_hbLink('SharpTeethExcerpt1','VidVert');">&quot;Sharp Teeth&quot; Excerpt #1</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescCFJRn7akXeQ">
+ Check out the book "Sharp Teeth" on Amazon:<br/>http://www.amazon.com/Sharp-Teeth-Toby-Barlow
+ </span>
+
+ <span id="RemainvidDescCFJRn7akXeQ" style="display: none">Check out the book "Sharp Teeth" on Amazon:<br/>http://www.amazon.com/Sharp-Teeth-Toby-Barlow/dp/0061430226/ ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1212767529&sr=8-1<br/><br/>Animation directed by Limbert Fabian. Produced by Matt Thunell. For more information go to sharpteeththebook.com</span>
+ <span id="MorevidDescCFJRn7akXeQ" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescCFJRn7akXeQ'); hideDiv('MorevidDescCFJRn7akXeQ'); hideDiv('BeginvidDescCFJRn7akXeQ'); showDiv('LessvidDescCFJRn7akXeQ'); return false;">more</a>)</span>
+ <span id="LessvidDescCFJRn7akXeQ" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescCFJRn7akXeQ'); hideDiv('LessvidDescCFJRn7akXeQ'); showDiv('BeginvidDescCFJRn7akXeQ'); showDiv('MorevidDescCFJRn7akXeQ'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/tobybarlowny">tobybarlowny</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 67,438<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.39928057554" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">01:33</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=1">Film & Animation</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=sNROaXA6OSI"><img src="http://i.ytimg.com/vi/sNROaXA6OSI/default.jpg" class="vimg120" title="Touring to Alaska on Vegetable Oil!" qliconalt="sNROaXA6OSI" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=sNROaXA6OSI" title="Touring to Alaska on Vegetable Oil!" onclick="_hbLink('TouringtoAlaskaonVegetableOil','VidVert');">Touring to Alaska on Vegetable Oil!</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=sNROaXA6OSI" title="Touring to Alaska on Vegetable Oil!" onclick="_hbLink('TouringtoAlaskaonVegetableOil','VidVert');">Touring to Alaska on Vegetable Oil!</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescsNROaXA6OSI">
+ This video is for Mrs. Aderman's 1st Period Environmental Science Class.<br/><br/>We are Mose Gi
+ </span>
+
+ <span id="RemainvidDescsNROaXA6OSI" style="display: none">This video is for Mrs. Aderman's 1st Period Environmental Science Class.<br/><br/>We are Mose Giganticus and The Emotron and this year we are touring to Alaska on Vegetable Oil.</span>
+ <span id="MorevidDescsNROaXA6OSI" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescsNROaXA6OSI'); hideDiv('MorevidDescsNROaXA6OSI'); hideDiv('BeginvidDescsNROaXA6OSI'); showDiv('LessvidDescsNROaXA6OSI'); return false;">more</a>)</span>
+ <span id="LessvidDescsNROaXA6OSI" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescsNROaXA6OSI'); hideDiv('LessvidDescsNROaXA6OSI'); showDiv('BeginvidDescsNROaXA6OSI'); showDiv('MorevidDescsNROaXA6OSI'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/kylemotron">kylemotron</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 122,748<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.44329896907" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">04:02</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=27">Education</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=6iC3b5JnSIE"><img src="http://i.ytimg.com/vi/6iC3b5JnSIE/default.jpg" class="vimg120" title="JCJC" qliconalt="6iC3b5JnSIE" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=6iC3b5JnSIE" title="JCJC" onclick="_hbLink('JCJC','VidVert');">JCJC</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=6iC3b5JnSIE" title="JCJC" onclick="_hbLink('JCJC','VidVert');">JCJC</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDesc6iC3b5JnSIE">
+ His name is Okotanpe. <br/>His mail addless is fuseloopa@hotmail.com <br/><br/>The name of this son
+ </span>
+
+ <span id="RemainvidDesc6iC3b5JnSIE" style="display: none">His name is Okotanpe. <br/>His mail addless is fuseloopa@hotmail.com <br/><br/>The name of this song is 300ml(milk).<br/>An artist name is Rei harakami. <br/>Check it out!</span>
+ <span id="MorevidDesc6iC3b5JnSIE" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDesc6iC3b5JnSIE'); hideDiv('MorevidDesc6iC3b5JnSIE'); hideDiv('BeginvidDesc6iC3b5JnSIE'); showDiv('LessvidDesc6iC3b5JnSIE'); return false;">more</a>)</span>
+ <span id="LessvidDesc6iC3b5JnSIE" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDesc6iC3b5JnSIE'); hideDiv('LessvidDesc6iC3b5JnSIE'); showDiv('BeginvidDesc6iC3b5JnSIE'); showDiv('MorevidDesc6iC3b5JnSIE'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/YoneyaYu">YoneyaYu</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 532,447<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-5.0" alt="4.83995523223" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">05:26</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=24">Entertainment</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=L9Wu1V1JAHw"><img src="http://i.ytimg.com/vi/L9Wu1V1JAHw/default.jpg" class="vimg120" title="Certainty In Freedom ~ A Song for Burma (Original Song)" qliconalt="L9Wu1V1JAHw" partner="true" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=L9Wu1V1JAHw" title="Certainty In Freedom ~ A Song for Burma (Original Song)" onclick="_hbLink('CertaintyInFreedomASongforBurmaOriginalSong','VidVert');">Certainty In Freedom ~ A Song fo...</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=L9Wu1V1JAHw" title="Certainty In Freedom ~ A Song for Burma (Original Song)" onclick="_hbLink('CertaintyInFreedomASongforBurmaOriginalSong','VidVert');">Certainty In Freedom ~ A Song for Burma (Original Song)</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescL9Wu1V1JAHw">
+ I'm not a particularly political person, by which I mean I'd sooner just not get involved
+ </span>
+
+ <span id="RemainvidDescL9Wu1V1JAHw" style="display: none">I'm not a particularly political person, by which I mean I'd sooner just not get involved in conflict, but I realise that, at times, things happen outside your control which will you to say something or do something.<br/><br/>I got a comment on my last song from 'gersing' asking me if I'd sing a song for the monks and people of Burma. At first I misunderstood the comment but then it clicked and I felt compelled to offer something.. anything. <br/><br/>I know this song is going to change nothing; and I'm cautious calling it a protest song as I don't understand the situation fully (and I wouldn't want to upset anyone), but this is a tune I wrote in response to being repressed (I'm whatever guise) and how beautiful 'freedom' really is. I don't think anyone will ever understand that term fully but by singing and writing and thinking and speaking we can come somewhere close I'm sure. <br/><br/>As a disclaimer, I'd say that, personally, the chords and melody are arbitrary; merely the carrier of the sentiment...<br/><br/>Changing the subject ever so slightly I just wanted to say a big thank you to everyone that's shown support; it's overwhelming. An apology to anyone I've not yet responded to.. I've never been very good at juggling my time but I will be in touch.<br/><br/>Thanks again...<br/><br/>_________________<br/>Certainty In Freedom<br/><br/>If I had the will to talk<br/>I wonder if you'd give a thought <br/>To what I had to say - help make it go away<br/><br/>Cos there's certainty in freedom<br/>And in that we must believe in<br/>Cos I saw on the news today<br/><br/>If I saw you in the street now<br/>Would I look the other way?<br/>I hope I'm strong enough to say - help make it go away<br/><br/>When all you see is hatred<br/>Spirits crushed and souls deflated<br/>Easy to leave it for another day<br/><br/>Peace is pushing for love<br/>Love is leading the way<br/>You should follow its path<br/>Darkness leads you astray<br/>Peace is pushing for love<br/>Love is leading the way<br/><br/>So this, my only voice to speak<br/>My message strong, my tone is weak<br/>I find it hard to say - help make it go away<br/><br/>And if I come across obtuse<br/>I urge you now to cut the noose<br/>Don't leave it for another day<br/><br/>Peace is pushing for love<br/>Love is leading the way<br/>You should follow its path<br/>Darkness leads you astray<br/>Peace is pushing for love<br/>Love is leading the way<br/><br/>If I had the will to talk<br/>I wonder if you'd give a thought <br/>To what I had to say - help make it go away<br/><br/>Cos there's certainty in freedom<br/>And in that we must believe in<br/>Cos I saw on the news today<br/><br/>Peace is pushing for love<br/>Love is leading the way<br/>You should follow its path<br/>Darkness leads you astray<br/>Peace is pushing for love<br/>Love is leading the way<br/><br/>_____________________<br/>Peace<br/><br/>Available on the 'Unequal Measures', available through http://www.krisrowley.com<br/>© Kris Rowley 2007</span>
+ <span id="MorevidDescL9Wu1V1JAHw" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescL9Wu1V1JAHw'); hideDiv('MorevidDescL9Wu1V1JAHw'); hideDiv('BeginvidDescL9Wu1V1JAHw'); showDiv('LessvidDescL9Wu1V1JAHw'); return false;">more</a>)</span>
+ <span id="LessvidDescL9Wu1V1JAHw" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescL9Wu1V1JAHw'); hideDiv('LessvidDescL9Wu1V1JAHw'); showDiv('BeginvidDescL9Wu1V1JAHw'); showDiv('MorevidDescL9Wu1V1JAHw'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/zzzzzzzzap">zzzzzzzzap</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 136,222<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.65044814341" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">03:55</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=10">Music</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=gQNY7Sti8FY"><img src="http://s4.ytimg.com/vi/gQNY7Sti8FY/default.jpg" class="vimg120" title="the world is at your fingertips" qliconalt="gQNY7Sti8FY" partner="true" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=gQNY7Sti8FY" title="the world is at your fingertips" onclick="_hbLink('theworldisatyourfingertips','VidVert');">the world is at your fingertips</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=gQNY7Sti8FY" title="the world is at your fingertips" onclick="_hbLink('theworldisatyourfingertips','VidVert');">the world is at your fingertips</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescgQNY7Sti8FY">
+ for the taking.
+ </span>
+
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/SupaDupaFlyGirl">SupaDupaFlyGirl</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 509,825<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.0" alt="3.91057134971" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">05:15</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=28">Science & Technology</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=rGUt7ropzNA"><img src="http://i.ytimg.com/vi/rGUt7ropzNA/default.jpg" class="vimg120" title="Aimee Mann Freeway Video Contest" qliconalt="rGUt7ropzNA" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=rGUt7ropzNA" title="Aimee Mann Freeway Video Contest" onclick="_hbLink('AimeeMannFreewayVideoContest','VidVert');">Aimee Mann Freeway Video Contest</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=rGUt7ropzNA" title="Aimee Mann Freeway Video Contest" onclick="_hbLink('AimeeMannFreewayVideoContest','VidVert');">Aimee Mann Freeway Video Contest</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescrGUt7ropzNA">
+ Want a chance to sing with Aimee Mann live? Go to http://www.youtube.com/group/aimeemannco
+ </span>
+
+ <span id="RemainvidDescrGUt7ropzNA" style="display: none">Want a chance to sing with Aimee Mann live? Go to http://www.youtube.com/group/aimeemanncontest and upload a video of yourself singing Aimee Mann's new song "Freeway."<br/><br/>Aimee Mann and SuperEgo Records will pick their favorite entry to be featured on YouTube and www.aimeemann.com. The winner will have an opportunity to sing live with Aimee at one of her upcoming shows. Ten runners-up will receive an autographed copy of Aimee's new CD, @#%&*! Smilers.<br/><br/>Entrants can get the lyrics, the instrumental version of "Freeway" and contest details at: http://www.aimeemann.com/freewaycontest/<br/>Submissions must be received by July 7th 2008</span>
+ <span id="MorevidDescrGUt7ropzNA" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescrGUt7ropzNA'); hideDiv('MorevidDescrGUt7ropzNA'); hideDiv('BeginvidDescrGUt7ropzNA'); showDiv('LessvidDescrGUt7ropzNA'); return false;">more</a>)</span>
+ <span id="LessvidDescrGUt7ropzNA" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescrGUt7ropzNA'); hideDiv('LessvidDescrGUt7ropzNA'); showDiv('BeginvidDescrGUt7ropzNA'); showDiv('MorevidDescrGUt7ropzNA'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/aimeemann">aimeemann</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 283,776<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.0" alt="3.79036827195" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">02:22</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=10">Music</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=tbEei0I3kMQ"><img src="http://i.ytimg.com/vi/tbEei0I3kMQ/default.jpg" class="vimg120" title="Interactive card trick" qliconalt="tbEei0I3kMQ" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=tbEei0I3kMQ" title="Interactive card trick" onclick="_hbLink('Interactivecardtrick','VidVert');">Interactive card trick</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=tbEei0I3kMQ" title="Interactive card trick" onclick="_hbLink('Interactivecardtrick','VidVert');">Interactive card trick</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDesctbEei0I3kMQ">
+ This is the first interactive video on YouTube!<br/>Have fun and enjoy the show<br/>you can see
+ </span>
+
+ <span id="RemainvidDesctbEei0I3kMQ" style="display: none">This is the first interactive video on YouTube!<br/>Have fun and enjoy the show<br/>you can see our magician site:<br/>orenshalom.co.il</span>
+ <span id="MorevidDesctbEei0I3kMQ" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDesctbEei0I3kMQ'); hideDiv('MorevidDesctbEei0I3kMQ'); hideDiv('BeginvidDesctbEei0I3kMQ'); showDiv('LessvidDesctbEei0I3kMQ'); return false;">more</a>)</span>
+ <span id="LessvidDesctbEei0I3kMQ" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDesctbEei0I3kMQ'); hideDiv('LessvidDesctbEei0I3kMQ'); showDiv('BeginvidDesctbEei0I3kMQ'); showDiv('MorevidDesctbEei0I3kMQ'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/werneroi">werneroi</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 3,155,063<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-3.5" alt="3.41263230956" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">01:10</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=22">People & Blogs</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=irDEzQovftM"><img src="http://i.ytimg.com/vi/irDEzQovftM/default.jpg" class="vimg120" title="Biggest drawing in the world" qliconalt="irDEzQovftM" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=irDEzQovftM" title="Biggest drawing in the world" onclick="_hbLink('Biggestdrawingintheworld','VidVert');">Biggest drawing in the world</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=irDEzQovftM" title="Biggest drawing in the world" onclick="_hbLink('Biggestdrawingintheworld','VidVert');">Biggest drawing in the world</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescirDEzQovftM">
+ making the biggest drawing in the world
+ </span>
+
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/erikbjgn">erikbjgn</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 971,773<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.54770783066" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">04:04</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=1">Film & Animation</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=iAKJKBCyPUY"><img src="http://i.ytimg.com/vi/iAKJKBCyPUY/default.jpg" class="vimg120" title="Checkmate" qliconalt="iAKJKBCyPUY" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=iAKJKBCyPUY" title="Checkmate" onclick="_hbLink('Checkmate','VidVert');">Checkmate</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=iAKJKBCyPUY" title="Checkmate" onclick="_hbLink('Checkmate','VidVert');">Checkmate</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDesciAKJKBCyPUY">
+ The Internets Celebrities Dallas Penn and Rafi Kam go in for an investigative report on Ch
+ </span>
+
+ <span id="RemainvidDesciAKJKBCyPUY" style="display: none">The Internets Celebrities Dallas Penn and Rafi Kam go in for an investigative report on Check-Cashing. Themes explored include usury, economic instability, commercial banks and their profit line, and the cycle of poverty. <br/><br/>Oh yeah, it's a comedy.<br/><br/>The video is shot on location in Bushwick and Carroll Gardens in Brooklyn, New York. Also stars special guest Internets Celebrity Ben Popken of Consumerist.com.<br/><br/>Directed by Casimir Nozkowski<br/>Shot by Ian Savage, Josh Weisbrot<br/>Music by El Keter; instrumental from song "The Bottom Line" off Sankofa's album The Tortoise Hustle. Used with full permission.<br/><br/>http://www.internetscelebrities.com</span>
+ <span id="MorevidDesciAKJKBCyPUY" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDesciAKJKBCyPUY'); hideDiv('MorevidDesciAKJKBCyPUY'); hideDiv('BeginvidDesciAKJKBCyPUY'); showDiv('LessvidDesciAKJKBCyPUY'); return false;">more</a>)</span>
+ <span id="LessvidDesciAKJKBCyPUY" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDesciAKJKBCyPUY'); hideDiv('LessvidDesciAKJKBCyPUY'); showDiv('BeginvidDesciAKJKBCyPUY'); showDiv('MorevidDesciAKJKBCyPUY'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/InternetsCelebrities">InternetsCel...</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 412,830<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.52936962751" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">09:45</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=25">News & Politics</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=yLCl0xIg5-0"><img src="http://i.ytimg.com/vi/yLCl0xIg5-0/default.jpg" class="vimg120" title="Stories from the Front lines, Part 1" qliconalt="yLCl0xIg5-0" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=yLCl0xIg5-0" title="Stories from the Front lines, Part 1" onclick="_hbLink('StoriesfromtheFrontlinesPart1','VidVert');">Stories from the Front lines, Pa...</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=yLCl0xIg5-0" title="Stories from the Front lines, Part 1" onclick="_hbLink('StoriesfromtheFrontlinesPart1','VidVert');">Stories from the Front lines, Part 1</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescyLCl0xIg50">
+ Stories from the men and women of the miltary, stationed in the Al Anbar Province. Right f
+ </span>
+
+ <span id="RemainvidDescyLCl0xIg50" style="display: none">Stories from the men and women of the miltary, stationed in the Al Anbar Province. Right from the mouths of the troops themselves. Part 1 of 4</span>
+ <span id="MorevidDescyLCl0xIg50" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescyLCl0xIg50'); hideDiv('MorevidDescyLCl0xIg50'); hideDiv('BeginvidDescyLCl0xIg50'); showDiv('LessvidDescyLCl0xIg50'); return false;">more</a>)</span>
+ <span id="LessvidDescyLCl0xIg50" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescyLCl0xIg50'); hideDiv('LessvidDescyLCl0xIg50'); showDiv('BeginvidDescyLCl0xIg50'); showDiv('MorevidDescyLCl0xIg50'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/3rdID8487">3rdID8487</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 367,189<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.0" alt="4.2188365651" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">10:35</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=25">News & Politics</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+
+
+
+
+ <div class="vlentry" >
+
+ <div class="vlcontainer"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a href="/watch?v=rFItE14EeSU"><img src="http://i.ytimg.com/vi/rFItE14EeSU/default.jpg" class="vimg120" title="Amazing video of multiple tornadoes in Northwest Kansas" qliconalt="rFItE14EeSU" partner="true" alt="video"></a></div></div> </div>
+
+ <div class="vldescbox">
+ <div class="vltitle">
+ <div class="vlshortTitle">
+ <a href="/watch?v=rFItE14EeSU" title="Amazing video of multiple tornadoes in Northwest Kansas" onclick="_hbLink('AmazingvideoofmultipletornadoesinNorthwestKansas','VidVert');">Amazing video of multiple tornad...</a>
+ </div>
+ <div class="vllongTitle">
+ <a href="/watch?v=rFItE14EeSU" title="Amazing video of multiple tornadoes in Northwest Kansas" onclick="_hbLink('AmazingvideoofmultipletornadoesinNorthwestKansas','VidVert');">Amazing video of multiple tornadoes in Northwest Kansas</a>
+ </div>
+ </div>
+
+ <div class="vldesc">
+
+
+ <span id="BeginvidDescrFItE14EeSU">
+ Video from TornadoVideos.net Live Stream Unit 3 of several tornadoes from close range.. In
+ </span>
+
+ <span id="RemainvidDescrFItE14EeSU" style="display: none">Video from TornadoVideos.net Live Stream Unit 3 of several tornadoes from close range.. Including one beautiful but strong rope and a large wedge tornado from within 1/2 mile. Check out TornadoVdeos.net for live streaming video, breaking weather news, and more extreme tornado footage.</span>
+ <span id="MorevidDescrFItE14EeSU" class="smallText">(<a href="#" class="eLink" onclick="showDiv('RemainvidDescrFItE14EeSU'); hideDiv('MorevidDescrFItE14EeSU'); hideDiv('BeginvidDescrFItE14EeSU'); showDiv('LessvidDescrFItE14EeSU'); return false;">more</a>)</span>
+ <span id="LessvidDescrFItE14EeSU" style="display: none" class="smallText">(<a href="#" class="eLink" onclick="hideDiv('RemainvidDescrFItE14EeSU'); hideDiv('LessvidDescrFItE14EeSU'); showDiv('BeginvidDescrFItE14EeSU'); showDiv('MorevidDescrFItE14EeSU'); return false;">less</a>)</span>
+
+
+
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+ </div>
+
+ <div class="vlfacets">
+ <div class="vladded">
+ </div>
+ <div><span class="grayText vlfromlbl">From:</span><span class="vlfrom"><a href="/user/TornadoVideosdotnet">TornadoVideo...</a></span></div>
+ <div class="clearL"></div>
+ <span class="grayText">Views:</span> 797,370<br/>
+
+ <div class="video-thumb-duration-rating">
+
+
+ <div>
+
+ <img class="ratingVS ratingVS-4.5" alt="4.28912552436" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+
+
+
+ </div>
+
+
+
+ <div class="runtime">07:10</div>
+ </div>
+
+ <div class="clear"></div>
+ <div class="vlcategory">
+ <span class="smgrayText">More in</span> <a href="/results?search_query=None&search_category=25">News & Politics</a>
+ </div>
+ </div>
+
+ <div class="vlclearaltl"></div>
+
+
+
+ </div> <!-- end vEntry -->
+
+
+ </div>
+ </div> <!-- end Video List -->
+ <div id="homepage-featured-more-bottom">
+ <div class="floatR"><a href="/browse?s=rf">See More Featured Videos</a></div>
+ <div class="clear"></div>
+ </div>
+</div>
+
+
+<div id="homepage-side-content" style="white-space: normal;">
+ <div>
+
+
+
+
+ <!-- Begin ad tag -->
+
+ <input type="hidden" id="pvaHl" value="en"/>
+ <input type="hidden" id="pvaTag" value="http://n4061ad.doubleclick.net/adj/com.ythome/_default;sz=399x299;kl=N;kga=-1;kgg=-1;tile=1;dcopt=ist;"/>
+ <input type="hidden" id="burl" value="http://www.youtube.com/pva/"/>
+ <input type="hidden" id="canv" value="False"/>
+ <div id="myAd_banner" style="visibility:hidden;height:35px;"></div>
+ <div id="myAd_pva">
+
+
+
+
+ <script type="text/javascript">
+ ord=Math.random()*10000000000000000 + 3;
+ if (false) {
+ ord = 1234567890;
+ }
+ document.write('<script language="JavaScript" src="http://n4061ad.doubleclick.net/adj/com.ythome/_default;sz=399x299;kl=N;kga=-1;kgg=-1;tile=1;dcopt=ist;ord=' + ord + '?" type="text/javascript"><\/script>');
+ </script>
+ <noscript><a
+ href="http://n4061ad.doubleclick.net/jump/_default;sz=399x299;ord=123456789?" target="_blank"><img
+ src="http://n4061ad.doubleclick.net/ad/_default;sz=399x299;ord=123456789?" width="399" height="299" border="0" alt=""></a>
+ </noscript>
+
+ </div>
+
+
+ <!-- End ad tag -->
+
+ </div>
+
+ <div class="homepage-content-block">
+ <div class="contentBox">
+ <div>
+ <div class="floatR"><span class="smallText"><b><a href="/signup">Sign Up</a> | <a href="http://help.youtube.com/support/youtube/bin/topic.py?topic=10546&amp;hl=en_US">Help</a></b></div>
+ <div class="floatL">
+ <span class="headerTitle homepage-block-heading-gray"> Login </span>
+ </div>
+ <div class="clear"></div>
+ </div>
+
+ <form method="post" name="loginForm" id="loginForm" action="signup">
+ <input type="hidden" name="action_login" value="1">
+ <table width="270">
+ <tr>
+ <td align="right"><label for="homeUsername"><span class="smallText"><b>Username:</b></span></label></td>
+ <td align="left"><input id="homeUsername" tabindex="101" class="smallText" type="text" size="16" name="username" value=""></td>
+ </tr>
+ <tr>
+ <td align="right"><label for="homePassword"><span class="smallText"><b>Password:</b></span></label></td>
+ <td align="left"><input id="homePassword" tabindex="102" class="smallText" type="password" size="16" name="password">
+ </tr>
+ <tr>
+ <td></td>
+ <td align="left">
+ <span><input type="submit" class="smallText" value="Login"></span>
+ </td>
+ </tr>
+ </table>
+ </form>
+ <div class="padT10 smallText">
+ <p align="center" class="marT0 marB0"><a href="/forgot_username?next=/">Forgot Username</a> | <a href="/forgot?next=/">Forgot Password</a></p>
+ </div>
+ <div class="homepage-border-dotted"></div>
+ <div class="alignC"><span class="smallText"><b><a href="
+https://www.google.com/accounts/ServiceLogin?service=youtube&hl=en_US&continue=http%3A//www.youtube.com/signup%3Fhl%3Den_US&passive=true">Login with your Google account</a>&nbsp; <a href="#" onClick="window.open('/t/help_gaia','login_help','width=580,height=480,resizable=yes,scrollbars=yes,status=0').focus();" rel="nofollow"><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" border="0" class="alignMid gaiaHelpBtn" alt=""></a></b></span></div>
+ </div>
+ </div> <!-- end homepage-content-block -->
+
+
+ <div class="homepage-content-block padT10">
+
+
+
+
+ <!-- Begin ad tag -->
+
+
+
+ <script type="text/javascript">
+ ord=Math.random()*10000000000000000 + 6;
+ if (false) {
+ ord = 1234567890;
+ }
+ document.write('<script language="JavaScript" src="http://n4061ad.doubleclick.net/adj/com.ythome/promo1;sz=300x50;kl=N;kga=-1;kgg=-1;tile=2;ord=' + ord + '?" type="text/javascript"><\/script>');
+ </script>
+ <noscript><a
+ href="http://n4061ad.doubleclick.net/jump/promo1;sz=300x50;ord=123456789?" target="_blank"><img
+ src="http://n4061ad.doubleclick.net/ad/promo1;sz=300x50;ord=123456789?" width="300" height="50" border="0" alt=""></a>
+ </noscript>
+
+
+ <!-- End ad tag -->
+
+ </div>
+
+ <div class="homepage-content-block padT10">
+
+
+
+
+ <!-- Begin ad tag -->
+
+
+
+ <script type="text/javascript">
+ ord=Math.random()*10000000000000000 + 6;
+ if (false) {
+ ord = 1234567890;
+ }
+ document.write('<script language="JavaScript" src="http://n4061ad.doubleclick.net/adj/com.ythome/promo3;sz=300x50;kl=N;kga=-1;kgg=-1;tile=4;ord=' + ord + '?" type="text/javascript"><\/script>');
+ </script>
+ <noscript><a
+ href="http://n4061ad.doubleclick.net/jump/promo3;sz=300x50;ord=123456789?" target="_blank"><img
+ src="http://n4061ad.doubleclick.net/ad/promo3;sz=300x50;ord=123456789?" width="300" height="50" border="0" alt=""></a>
+ </noscript>
+
+
+ <!-- End ad tag -->
+
+ </div>
+
+ <div class="homepage-side-block padT10">
+ <div class="homepage-yellow-block">
+ <div class="homepage-block-heading" style="color:#CC6600">What's New</div>
+
+ <div class="homepage-whatsnew-entry">
+ <div class="homepage-whatsnew-image"><a href="/t/annotations_about"><img src="http://s.ytimg.com/yt/img/whats_new/annotation-vfl42087.gif" border="0" width="30" height="37"/></a></div>
+ <div class="homepage-whatsnew-desc">
+ <b><a href="/t/annotations_about">Video Annotations</a></b><br/>Add interactive commentary and links to your videos
+ </div>
+ </div><div class="clear"></div>
+
+ <div class="homepage-whatsnew-entry">
+ <div class="homepage-whatsnew-image"><a href="/address_book"><img src="http://s.ytimg.com/yt/img/whats_new/addybook-vfl39351.gif" border="0" width="30" height="37"/></a></div>
+ <div class="homepage-whatsnew-desc">
+ <b><a href="/address_book">New Address Book</a></b><br/>Organizing your YouTube friends and contacts just got a lot simpler
+ </div>
+ </div><div class="clear"></div>
+
+ <div class="homepage-whatsnew-entry">
+ <div class="homepage-whatsnew-image"><a href="/inbox"><img src="http://s.ytimg.com/yt/img/whats_new/inbox-vfl39351.gif" border="0" width="30" height="37"/></a></div>
+ <div class="homepage-whatsnew-desc">
+ <b><a href="/inbox">Updated Inbox</a></b><br/>Manage your messages and invites with ease
+ </div>
+ </div><div class="clear"></div>
+
+
+ <div class="homepage-whatsnew-entry">
+ <div class="homepage-whatsnew-image"><a href="/mobile"><img src="http://s.ytimg.com/yt/img/whats_new/pic_home_mobile_30x37-vfl37458.gif" border="0" width="30" height="37"/></a></div>
+ <div class="homepage-whatsnew-desc">
+ <b><a href="/mobile">YouTube Mobile</a></b><br/> Watch and upload YouTube videos on your mobile device.
+ </div>
+ </div><div class="clear"></div>
+
+ <div class="bottomBorderDotted"></div>
+ <b><a href="/blog" style="color:#CC6600">Hear Ye, Hear Ye: Calling all Reporters</a></b><br>
+ Today we announce the launch of a new type of YouTube account: the Reporter. Reporter channels are just like the other YouTube channel types, but are specifically intended for citizens and profess...
+ <div class="alignR padT5">
+ <a href="/blog" style="color:#CC6600">Read more in our Blog</a>
+ </div>
+ <div style="font-size: 1px; height: 1px;"><br/></div>
+ </div><img class="homepage-yellow-block-bot" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" />
+</div>
+
+
+ <div class="homepage-side-block">
+
+
+
+
+ <!-- Begin ad tag -->
+
+
+
+ <script type="text/javascript">
+ ord=Math.random()*10000000000000000 + 6;
+ if (false) {
+ ord = 1234567890;
+ }
+ document.write('<script language="JavaScript" src="http://n4061ad.doubleclick.net/adj/com.ythome/promo2;sz=300x50;kl=N;kga=-1;kgg=-1;tile=3;ord=' + ord + '?" type="text/javascript"><\/script>');
+ </script>
+ <noscript><a
+ href="http://n4061ad.doubleclick.net/jump/promo2;sz=300x50;ord=123456789?" target="_blank"><img
+ src="http://n4061ad.doubleclick.net/ad/promo2;sz=300x50;ord=123456789?" width="300" height="50" border="0" alt=""></a>
+ </noscript>
+
+
+ <!-- End ad tag -->
+
+ </div>
+
+
+</div> <!-- end homepage-side-content -->
+
+<div class="clear"></div>
+
+
+
+ <div class="clear"></div>
+ <div id="footer">
+ <div class="search">
+ <div class="promo">
+ <a href="/youchoose" onclick="_hbLink('FooterPromo','Footer');"><img id="debates_footer_img" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" alt="footer-promo" /></a>
+ <a href="/youchoose" onclick="_hbLink('FooterPromo','Footer');">Face The Candidates</a>
+ </div>
+ <form autocomplete="off" name="footer-search-form" method="get" action="/results" style="width: 73.5%;">
+ <a href="http://www.google.com/webmasters/igoogle/youtube.html"><img id="igoogle_footer_img" src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" alt=""/> <em id="igoogle_footer_text">Add to iGoogle</em></a>
+ <input type="text" name="search_query" maxlength="128" class="query" onkeyup="goog.i18n.bidi.setDirAttribute(event,this)" value="" id="footer-search-term">
+ <select class="search-type" name="search_type">
+ <option value="">Videos</option>
+ <option value="search_users" >Channels</option>
+ </select>
+ <input type="submit" name="search" value="Search" class="submit-button">
+ </form>
+ </div>
+ <div class="links">
+ <table cellpadding="0" cellspacing="0">
+ <tr>
+ <th colspan="2">Your Account</th>
+ <th class="separator" colspan="2">Help &amp; Info</th>
+ <th class="separator" colspan="2">YouTube</th>
+ </tr>
+ <tr>
+ <td><a href="/my_videos">Videos</a></td>
+ <td><a href="/inbox">Inbox</a></td>
+ <td class="separator"><a href="http://help.youtube.com/support/youtube/bin/static.py?page=start.cs&amp;hl=en_US">Help Resources</a></td>
+ <td><a href="/t/safety">Safety Tips</a></td>
+ <td class="separator"><a href="/t/about">Company Info</a></td>
+ <td><a href="/press_room">Press</a></td>
+ </tr>
+ <tr>
+ <td><a href="/my_favorites">Favorites</a></td>
+ <td><a href="/subscription_center">Subscriptions</a></td>
+ <td class="separator"><a href="/t/video_toolbox">Video Toolbox</a></td>
+ <td><a href="/t/dmca_policy">Copyright Notices</a></td>
+ <td class="separator"><a href="/testtube">TestTube</a></td>
+ <td><a href="/t/contact_us">Contact</a></td>
+ </tr>
+ <tr>
+ <td><a href="/my_playlists">Playlists</a></td>
+ <td><a href="/my_account">more...</a></td>
+ <td class="separator"><a href="/dev">Developer APIs</a></td>
+ <td><a href="/t/community_guidelines">Community Guidelines</a></td>
+ <td class="separator"><a href="/t/terms">Terms of Use</a></td>
+ <td>
+ <a href="/blog">Blog</a>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">&nbsp;</td>
+ <td class="separator"><a href="/advertise">Advertising</a></td>
+ <td><a href="/youtubeonyoursite">YouTube On Your Site</a></td>
+ <td class="separator"><a href="/t/privacy">Privacy Policy</a></td>
+ <td>
+ <a href="http://www.google.com/jobs/youtube">Jobs</a><br/>
+ </td>
+ </tr>
+
+
+
+ </table>
+ </div>
+ </div>
+ <div id="copyright">
+ &copy; 2008 YouTube, LLC
+ </div>
+
+
+</div> <!-- end baseDiv -->
+
+</body>
+<script type="text/javascript">
+ window.setTimeout('window.google.ac.install(document.searchForm,document.searchForm.search_query,"yt",true,"close",true,"Suggestions")',100);
+</script>
+
+
+
+</html> \ No newline at end of file
diff --git a/examples/xml/rsslisting/main.cpp b/examples/xml/rsslisting/main.cpp
new file mode 100644
index 0000000000..011569f2b6
--- /dev/null
+++ b/examples/xml/rsslisting/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+main.cpp
+
+Provides the main function for the RSS news reader example.
+*/
+
+#include <QtGui>
+
+#include "rsslisting.h"
+
+/*!
+ Create an application and a main widget. Open the main widget for
+ user input, and exit with an appropriate return value when it is
+ closed.
+*/
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ RSSListing *rsslisting = new RSSListing;
+ rsslisting->show();
+ return app.exec();
+}
diff --git a/examples/xml/rsslisting/rsslisting.cpp b/examples/xml/rsslisting/rsslisting.cpp
new file mode 100644
index 0000000000..5840f08d09
--- /dev/null
+++ b/examples/xml/rsslisting/rsslisting.cpp
@@ -0,0 +1,247 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+rsslisting.cpp
+
+Provides a widget for displaying news items from RDF news sources.
+RDF is an XML-based format for storing items of information (see
+http://www.w3.org/RDF/ for details).
+
+The widget itself provides a simple user interface for specifying
+the URL of a news source, and controlling the downloading of news.
+
+The widget downloads and parses the XML asynchronously, feeding the
+data to an XML reader in pieces. This allows the user to interrupt
+its operation, and also allows very large data sources to be read.
+*/
+
+
+#include <QtCore>
+#include <QtGui>
+#include <QtNetwork>
+
+#include "rsslisting.h"
+
+
+/*
+ Constructs an RSSListing widget with a simple user interface, and sets
+ up the XML reader to use a custom handler class.
+
+ The user interface consists of a line edit, a push button, and a
+ list view widget. The line edit is used for entering the URLs of news
+ sources; the push button starts the process of reading the
+ news.
+*/
+
+RSSListing::RSSListing(QWidget *parent)
+ : QWidget(parent), currentReply(0)
+{
+ lineEdit = new QLineEdit(this);
+ lineEdit->setText("http://labs.qt.nokia.com/blogs/feed");
+
+ fetchButton = new QPushButton(tr("Fetch"), this);
+
+ treeWidget = new QTreeWidget(this);
+ connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)),
+ this, SLOT(itemActivated(QTreeWidgetItem*)));
+ QStringList headerLabels;
+ headerLabels << tr("Title") << tr("Link");
+ treeWidget->setHeaderLabels(headerLabels);
+ treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
+
+ connect(&manager, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(finished(QNetworkReply*)));
+
+ connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch()));
+ connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch()));
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ QHBoxLayout *hboxLayout = new QHBoxLayout;
+
+ hboxLayout->addWidget(lineEdit);
+ hboxLayout->addWidget(fetchButton);
+
+ layout->addLayout(hboxLayout);
+ layout->addWidget(treeWidget);
+
+ setWindowTitle(tr("RSS listing example"));
+ resize(640,480);
+}
+
+/*
+ Starts the network request and connects the needed signals
+*/
+void RSSListing::get(const QUrl &url)
+{
+ QNetworkRequest request(url);
+ if (currentReply) {
+ currentReply->disconnect(this);
+ currentReply->deleteLater();
+ }
+ currentReply = manager.get(request);
+ connect(currentReply, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(currentReply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
+ connect(currentReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));
+}
+
+/*
+ Starts fetching data from a news source specified in the line
+ edit widget.
+
+ The line edit is made read only to prevent the user from modifying its
+ contents during the fetch; this is only for cosmetic purposes.
+ The fetch button is disabled, the list view is cleared, and we
+ define the last list view item to be 0, meaning that there are no
+ existing items in the list.
+
+ A URL is created with the raw contents of the line edit and
+ a get is initiated.
+*/
+
+void RSSListing::fetch()
+{
+ lineEdit->setReadOnly(true);
+ fetchButton->setEnabled(false);
+ treeWidget->clear();
+
+ xml.clear();
+
+ QUrl url(lineEdit->text());
+ get(url);
+}
+
+void RSSListing::metaDataChanged()
+{
+ QUrl redirectionTarget = currentReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+ if (redirectionTarget.isValid()) {
+ get(redirectionTarget);
+ }
+}
+
+/*
+ Reads data received from the RDF source.
+
+ We read all the available data, and pass it to the XML
+ stream reader. Then we call the XML parsing function.
+*/
+
+void RSSListing::readyRead()
+{
+ int statusCode = currentReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (statusCode >= 200 && statusCode < 300) {
+ QByteArray data = currentReply->readAll();
+ xml.addData(data);
+ parseXml();
+ }
+}
+
+/*
+ Finishes processing an HTTP request.
+
+ The default behavior is to keep the text edit read only.
+
+ If an error has occurred, the user interface is made available
+ to the user for further input, allowing a new fetch to be
+ started.
+
+ If the HTTP get request has finished, we make the
+ user interface available to the user for further input.
+*/
+
+void RSSListing::finished(QNetworkReply *reply)
+{
+ Q_UNUSED(reply);
+ lineEdit->setReadOnly(false);
+ fetchButton->setEnabled(true);
+}
+
+
+/*
+ Parses the XML data and creates treeWidget items accordingly.
+*/
+void RSSListing::parseXml()
+{
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.isStartElement()) {
+ if (xml.name() == "item")
+ linkString = xml.attributes().value("rss:about").toString();
+ currentTag = xml.name().toString();
+ } else if (xml.isEndElement()) {
+ if (xml.name() == "item") {
+
+ QTreeWidgetItem *item = new QTreeWidgetItem;
+ item->setText(0, titleString);
+ item->setText(1, linkString);
+ treeWidget->addTopLevelItem(item);
+
+ titleString.clear();
+ linkString.clear();
+ }
+
+ } else if (xml.isCharacters() && !xml.isWhitespace()) {
+ if (currentTag == "title")
+ titleString += xml.text().toString();
+ else if (currentTag == "link")
+ linkString += xml.text().toString();
+ }
+ }
+ if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
+ qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString();
+ }
+}
+
+/*
+ Open the link in the browser
+*/
+void RSSListing::itemActivated(QTreeWidgetItem * item)
+{
+ QDesktopServices::openUrl(QUrl(item->text(1)));
+}
+
+void RSSListing::error(QNetworkReply::NetworkError)
+{
+ qWarning("error retrieving RSS feed");
+ currentReply->disconnect(this);
+ currentReply->deleteLater();
+ currentReply = 0;
+}
diff --git a/examples/xml/rsslisting/rsslisting.h b/examples/xml/rsslisting/rsslisting.h
new file mode 100644
index 0000000000..98254f839b
--- /dev/null
+++ b/examples/xml/rsslisting/rsslisting.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RSSLISTING_H
+#define RSSLISTING_H
+
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QWidget>
+#include <QBuffer>
+#include <QXmlStreamReader>
+#include <QUrl>
+
+QT_BEGIN_NAMESPACE
+class QLineEdit;
+class QTreeWidget;
+class QTreeWidgetItem;
+class QPushButton;
+QT_END_NAMESPACE
+
+class RSSListing : public QWidget
+{
+ Q_OBJECT
+public:
+ RSSListing(QWidget *widget = 0);
+
+public slots:
+ void fetch();
+ void finished(QNetworkReply *reply);
+ void readyRead();
+ void metaDataChanged();
+ void itemActivated(QTreeWidgetItem * item);
+ void error(QNetworkReply::NetworkError);
+
+private:
+ void parseXml();
+ void get(const QUrl &url);
+
+ QXmlStreamReader xml;
+ QString currentTag;
+ QString linkString;
+ QString titleString;
+
+ QNetworkAccessManager manager;
+ QNetworkReply *currentReply;
+
+ QLineEdit *lineEdit;
+ QTreeWidget *treeWidget;
+ QPushButton *fetchButton;
+};
+
+#endif
+
diff --git a/examples/xml/rsslisting/rsslisting.pro b/examples/xml/rsslisting/rsslisting.pro
new file mode 100644
index 0000000000..01bc9e2ad6
--- /dev/null
+++ b/examples/xml/rsslisting/rsslisting.pro
@@ -0,0 +1,12 @@
+HEADERS += rsslisting.h
+SOURCES += main.cpp rsslisting.cpp
+QT += network xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/rsslisting
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS rsslisting.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/rsslisting
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+
diff --git a/examples/xml/saxbookmarks/frank.xbel b/examples/xml/saxbookmarks/frank.xbel
new file mode 100644
index 0000000000..6bd63b8b07
--- /dev/null
+++ b/examples/xml/saxbookmarks/frank.xbel
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="yes">
+ <title>Literate Programming</title>
+ <bookmark href="http://www.vivtek.com/litprog.html">
+ <title>Synopsis of Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html">
+ <title>Literate Programming: Propaganda and Tools</title>
+ </bookmark>
+ <bookmark href="http://www.isy.liu.se/%7Eturbell/litprog/">
+ <title>Literate Programming by Henrik Turbell</title>
+ </bookmark>
+ <bookmark href="http://www.desy.de/user/projects/LitProg.html">
+ <title>Literate Programming Library</title>
+ </bookmark>
+ <bookmark href="http://www.loria.fr/services/tex/english/litte.html">
+ <title>Literate Programming Basics</title>
+ </bookmark>
+ <bookmark href="http://ei.cs.vt.edu/%7Ecs5014/courseNotes/4.LiterateProgramming/literate_prog.html">
+ <title>Literate Programming Overview</title>
+ </bookmark>
+ <bookmark href="http://www.perl.com/pub/a/tchrist/litprog.html">
+ <title>POD is not Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://www.cornellcollege.edu/%7Eltabak/publications/articles/swsafety.html">
+ <title>Computers That We Can Count On</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/litpro/issues-and-problems.html">
+ <title>Literate Programming - Issues and Problems</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?LiterateProgramming">
+ <title>Literate Programming - Wiki Pages</title>
+ </bookmark>
+ <bookmark href="http://developers.slashdot.org/developers/02/05/19/2216233.shtml">
+ <title>What is well-commented code?</title>
+ </bookmark>
+ <bookmark href="http://liinwww.ira.uka.de/bibliography/SE/litprog.html">
+ <title>Bibliography on literate programming - A searchable bibliography</title>
+ </bookmark>
+ <bookmark href="http://www2.umassd.edu/SWPI/ProcessBibliography/bib-codereading.html">
+ <title>Program comprehension and code reading bibliography</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/elucidative-programming/">
+ <title>Elucidative Programming</title>
+ </bookmark>
+ <bookmark href="http://www.msu.edu/%7Epfaffben/avl/index.html">
+ <title>AVL Trees (TexiWeb)</title>
+ </bookmark>
+ <bookmark href="http://literate-programming.wikiverse.org/">
+ <title>Literate Programming on Wikiverse</title>
+ </bookmark>
+ <bookmark href="http://www.pbrt.org/">
+ <title>Physically Based Rendering: From Theory to Implementation</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Useful C++ Links</title>
+ <folder folded="no">
+ <title>STL</title>
+ <bookmark href="http://www.sgi.com/tech/stl/table_of_contents.html">
+ <title>STL Reference Documentation</title>
+ </bookmark>
+ <bookmark href="http://www.yrl.co.uk/~phil/stl/stl.htmlx">
+ <title>STL Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.cppreference.com/cpp_stl.html">
+ <title>STL Reference</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Qt</title>
+ <bookmark href="http://qt.nokia.com/doc/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>Qt Home Page</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>IOStreams</title>
+ <bookmark href="http://www.cplusplus.com/ref/iostream/index.html">
+ <title>IO Stream Library</title>
+ </bookmark>
+ <bookmark href="http://courses.cs.vt.edu/~cs2604/fall01/binio.html">
+ <title>Binary I/O</title>
+ </bookmark>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/input-output.html">
+ <title>I/O Stream FAQ</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>gdb</title>
+ <bookmark href="http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html">
+ <title>GDB Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.gnu.org/manual/gdb-4.17/html_mono/gdb.html">
+ <title>Debugging with GDB</title>
+ </bookmark>
+ <bookmark href="http://www.cs.washington.edu/orgs/acm/tutorials/dev-in-unix/gdb-refcard.pdf">
+ <title>GDB Quick Reference Page (PDF) (Handy)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Classes and Constructors</title>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/ctors.html">
+ <title>Constructor FAQ</title>
+ </bookmark>
+ <bookmark href="http://www.juicystudio.com/tutorial/cpp/index.html">
+ <title>Organizing Classes</title>
+ </bookmark>
+ </folder>
+ </folder>
+ <folder folded="yes">
+ <title>Software Documentation or System Documentation</title>
+ <bookmark href="http://www.martinfowler.com/distributedComputing/thud.html">
+ <title>The Almighty Thud</title>
+ </bookmark>
+ <bookmark href="http://msdn.microsoft.com/library/techart/cfr.htm">
+ <title>Microsoft Coding Techniques and Programming Practices</title>
+ </bookmark>
+ <bookmark href="http://www.bearcave.com/software/prog_docs.html">
+ <title>Software and Documentation</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?TheSourceCodeIsTheDesign">
+ <title>The Source Code is the Design</title>
+ </bookmark>
+ <bookmark href="http://www.bleading-edge.com/Publications/C++Journal/Cpjour2.htm">
+ <title>What is Software Design?</title>
+ </bookmark>
+ <bookmark href="http://www.mindprod.com/unmain.html">
+ <title>How To Write Unmaintainable Code</title>
+ </bookmark>
+ <bookmark href="http://www.idinews.com/selfDoc.html">
+ <title>Self Documenting Program Code Remains a Distant Goal</title>
+ </bookmark>
+ <bookmark href="http://www.sdmagazine.com/documents/s=730/sdm0106m/0106m.htm">
+ <title>Place Tab A in Slot B</title>
+ </bookmark>
+ <bookmark href="http://www.holub.com/class/uml/uml.html">
+ <title>UML Reference Card</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>TeX Resources</title>
+ <bookmark href="http://www.tug.org/">
+ <title>The TeX User's Group</title>
+ </bookmark>
+ <bookmark href="http://www.miktex.org/">
+ <title>MikTeX website</title>
+ </bookmark>
+ <bookmark href="http://cm.bell-labs.com/who/hobby/MetaPost.html">
+ <title>MetaPost website</title>
+ </bookmark>
+ <bookmark href="http://pauillac.inria.fr/%7Emaranget/hevea/">
+ <title>HEVEA is a quite complete and fast LATEX to HTML translator</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Portable Document Format (PDF)</title>
+ <bookmark href="http://www.adobe.com/">
+ <title>Adobe - The postscript and PDF standards</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html">
+ <title>Reference Manual Portable Document Format</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/acrosdk/main.html">
+ <title>Adobe Acrobat Software Development Kit</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Literature Sites</title>
+ <bookmark href="http://www.cc.columbia.edu/cu/libraries/subjects/speccol.html">
+ <title>Guide to Special Collections (Columbia University)</title>
+ </bookmark>
+ <bookmark href="http://www.ipl.org/ref/litcrit/">
+ <title>Literary Criticism on the Web from the Internet Public Library</title>
+ </bookmark>
+ <bookmark href="http://www.victorianweb.org/">
+ <title>Victorian Web.</title>
+ </bookmark>
+ <bookmark href="http://vos.ucsb.edu/">
+ <title>Voice of the Shuttle.</title>
+ </bookmark>
+ <bookmark href="http://www.modjourn.brown.edu/">
+ <title>Modernist Journals Project</title>
+ </bookmark>
+ <bookmark href="http://www.poetspath.com">
+ <title>Museum of American Poetics</title>
+ </bookmark>
+ <bookmark href="http://www.english.uiuc.edu/maps/">
+ <title>Modern American Poetry</title>
+ </bookmark>
+ <bookmark href="http://www.findarticles.com/">
+ <title>FindArticles.com</title>
+ </bookmark>
+ <bookmark href="http://www.literaryhistory.com">
+ <title>Literary History</title>
+ </bookmark>
+ <bookmark href="http://www.litencyc.com/LitEncycFrame.htm">
+ <title>Literary Encyclopedia</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://texts.cdlib.org/ucpress/">
+ <title>The University of California Press</title>
+ </bookmark>
+ <bookmark href="http://www.letrs.indiana.edu/web/w/wright2/">
+ <title>Wright American Fiction, 1851-1875</title>
+ </bookmark>
+ <bookmark href="http://docsouth.unc.edu/">
+ <title>Documenting the American South: Beginnings to 1920</title>
+ </bookmark>
+ <bookmark href="http://etext.lib.virginia.edu/eng-on.html">
+ <title>Electronic Text Center at the University of Virginia</title>
+ </bookmark>
+ <bookmark href="http://digital.nypl.org/schomburg/writers_aa19/">
+ <title>The Schomburg Center for Research in Black Culture</title>
+ </bookmark>
+ <bookmark href="http://www.infomotions.com/alex2/">
+ <title>Alex Catalogue of Electronic Texts.</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/saxbookmarks/jennifer.xbel b/examples/xml/saxbookmarks/jennifer.xbel
new file mode 100644
index 0000000000..d6a5b41d05
--- /dev/null
+++ b/examples/xml/saxbookmarks/jennifer.xbel
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="no">
+ <title>Qt Resources</title>
+ <folder folded="yes">
+ <title>Qt Partners</title>
+ <bookmark href="http://partners.trolltech.com/partners/training.html">
+ <title>Training Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/service.html">
+ <title>Consultants and System Integrators</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/tech.html">
+ <title>Technology Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/resellers.html">
+ <title>Value Added Resellers (VARs)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Community Resources</title>
+ <bookmark href="http://www.qtforum.org/">
+ <title>QtForum.org</title>
+ </bookmark>
+ <bookmark href="http://www.digitalfanatics.org/projects/qt_tutorial/">
+ <title>The Independent Qt Tutorial</title>
+ </bookmark>
+ <bookmark href="http://prog.qt.free.fr/">
+ <title>French PROG.Qt</title>
+ </bookmark>
+ <bookmark href="http://www.qtforum.de/">
+ <title>German Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://www.korone.net/">
+ <title>Korean Qt Community Site</title>
+ </bookmark>
+ <bookmark href="http://prog.org.ru/forum/forum_14.html">
+ <title>Russian Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://qt4.digitalfanatics.org/">
+ <title>Digitalfanatics: The QT 4 Resource Center</title>
+ </bookmark>
+ <bookmark href="http://www.qtquestions.org/">
+ <title>QtQuestions</title>
+ </bookmark>
+ </folder>
+ <bookmark href="http://qt.nokia.com/doc/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>qt home page</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/developer/faqs/">
+ <title>Frequently Asked Questions</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Online Dictionaries</title>
+ <bookmark href="http://www.dictionary.com/">
+ <title>Dictionary.com</title>
+ </bookmark>
+ <bookmark href="http://www.m-w.com/">
+ <title>Merriam-Webster Online</title>
+ </bookmark>
+ <bookmark href="http://dictionary.cambridge.org/">
+ <title>Cambridge Dictionaries Online</title>
+ </bookmark>
+ <bookmark href="http://www.onelook.com/">
+ <title>OneLook Dictionary Search</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="www.iee.et.tu-dresden.de/">
+ <title>The New English-German Dictionary</title>
+ </bookmark>
+ <bookmark href="http://dict.tu-chemnitz.de/">
+ <title>TU Chemnitz German-English Dictionary</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://atilf.atilf.fr/tlf.htm">
+ <title>Trésor de la Langue Française informatisé</title>
+ </bookmark>
+ <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/">
+ <title>Dictionnaire de l'Académie Française</title>
+ </bookmark>
+ <bookmark href="http://elsap1.unicaen.fr/cgi-bin/cherches.cgi">
+ <title>Dictionnaire des synonymes</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/saxbookmarks/main.cpp b/examples/xml/saxbookmarks/main.cpp
new file mode 100644
index 0000000000..5d70ec89a5
--- /dev/null
+++ b/examples/xml/saxbookmarks/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+#if defined(Q_OS_SYMBIAN)
+ mainWin.showFullScreen();
+#else
+ mainWin.show();
+#endif
+ mainWin.open();
+ return app.exec();
+}
diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp
new file mode 100644
index 0000000000..e5300121e5
--- /dev/null
+++ b/examples/xml/saxbookmarks/mainwindow.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "xbelgenerator.h"
+#include "xbelhandler.h"
+
+MainWindow::MainWindow()
+{
+ QStringList labels;
+ labels << tr("Title") << tr("Location");
+
+ treeWidget = new QTreeWidget;
+ treeWidget->header()->setResizeMode(QHeaderView::Stretch);
+ treeWidget->setHeaderLabels(labels);
+ setCentralWidget(treeWidget);
+
+ createActions();
+ createMenus();
+
+ statusBar()->showMessage(tr("Ready"));
+
+ setWindowTitle(tr("SAX Bookmarks"));
+ resize(480, 320);
+}
+
+void MainWindow::open()
+{
+#if defined(Q_OS_SYMBIAN)
+ // Look for bookmarks on the same drive where the application is installed to,
+ // if drive is not read only. QDesktopServices::DataLocation does this check,
+ // and returns writable drive.
+ QString bookmarksFolder =
+ QDesktopServices::storageLocation(QDesktopServices::DataLocation).left(1);
+ bookmarksFolder.append(":/Data/qt/saxbookmarks");
+ QDir::setCurrent(bookmarksFolder);
+#endif
+ QString fileName =
+ QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ treeWidget->clear();
+
+ XbelHandler handler(treeWidget);
+ QXmlSimpleReader reader;
+ reader.setContentHandler(&handler);
+ reader.setErrorHandler(&handler);
+
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SAX Bookmarks"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ QXmlInputSource xmlInputSource(&file);
+ if (reader.parse(xmlInputSource))
+ statusBar()->showMessage(tr("File loaded"), 2000);
+}
+
+void MainWindow::saveAs()
+{
+ QString fileName =
+ QFileDialog::getSaveFileName(this, tr("Save Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("SAX Bookmarks"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ XbelGenerator generator(treeWidget);
+ if (generator.write(&file))
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About SAX Bookmarks"),
+ tr("The <b>SAX Bookmarks</b> example demonstrates how to use Qt's "
+ "SAX classes to read XML documents and how to generate XML by "
+ "hand."));
+}
+
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addAction(exitAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
diff --git a/examples/xml/saxbookmarks/mainwindow.h b/examples/xml/saxbookmarks/mainwindow.h
new file mode 100644
index 0000000000..3313d8f574
--- /dev/null
+++ b/examples/xml/saxbookmarks/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+QT_END_NAMESPACE
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void open();
+ void saveAs();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+
+ QTreeWidget *treeWidget;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *openAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+
+#endif
diff --git a/examples/xml/saxbookmarks/saxbookmarks.pro b/examples/xml/saxbookmarks/saxbookmarks.pro
new file mode 100644
index 0000000000..3091947afc
--- /dev/null
+++ b/examples/xml/saxbookmarks/saxbookmarks.pro
@@ -0,0 +1,28 @@
+HEADERS = mainwindow.h \
+ xbelgenerator.h \
+ xbelhandler.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ xbelgenerator.cpp \
+ xbelhandler.cpp
+QT += xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/saxbookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS saxbookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/saxbookmarks
+INSTALLS += target sources
+
+wince*: {
+ addFiles.files = frank.xbel jennifer.xbel
+ addFiles.path = "\\My Documents"
+ DEPLOYMENT += addFiles
+}
+
+symbian: {
+ TARGET.UID3 = 0xA000C60A
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ addFiles.files = frank.xbel jennifer.xbel
+ addFiles.path = /data/qt/saxbookmarks
+ DEPLOYMENT += addFiles
+}
diff --git a/examples/xml/saxbookmarks/xbelgenerator.cpp b/examples/xml/saxbookmarks/xbelgenerator.cpp
new file mode 100644
index 0000000000..a0bfe67f69
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelgenerator.cpp
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbelgenerator.h"
+
+XbelGenerator::XbelGenerator(QTreeWidget *treeWidget)
+ : treeWidget(treeWidget)
+{
+}
+
+bool XbelGenerator::write(QIODevice *device)
+{
+ out.setDevice(device);
+ out.setCodec("UTF-8");
+ out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ << "<!DOCTYPE xbel>\n"
+ << "<xbel version=\"1.0\">\n";
+
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
+ generateItem(treeWidget->topLevelItem(i), 1);
+
+ out << "</xbel>\n";
+ return true;
+}
+
+QString XbelGenerator::indent(int depth)
+{
+ const int IndentSize = 4;
+ return QString(IndentSize * depth, ' ');
+}
+
+QString XbelGenerator::escapedText(const QString &str)
+{
+ QString result = str;
+ result.replace("&", "&amp;");
+ result.replace("<", "&lt;");
+ result.replace(">", "&gt;");
+ return result;
+}
+
+QString XbelGenerator::escapedAttribute(const QString &str)
+{
+ QString result = escapedText(str);
+ result.replace("\"", "&quot;");
+ result.prepend("\"");
+ result.append("\"");
+ return result;
+}
+
+void XbelGenerator::generateItem(QTreeWidgetItem *item, int depth)
+{
+ QString tagName = item->data(0, Qt::UserRole).toString();
+ if (tagName == "folder") {
+ bool folded = !treeWidget->isItemExpanded(item);
+ out << indent(depth) << "<folder folded=\"" << (folded ? "yes" : "no")
+ << "\">\n"
+ << indent(depth + 1) << "<title>" << escapedText(item->text(0))
+ << "</title>\n";
+
+ for (int i = 0; i < item->childCount(); ++i)
+ generateItem(item->child(i), depth + 1);
+
+ out << indent(depth) << "</folder>\n";
+ } else if (tagName == "bookmark") {
+ out << indent(depth) << "<bookmark";
+ if (!item->text(1).isEmpty())
+ out << " href=" << escapedAttribute(item->text(1));
+ out << ">\n"
+ << indent(depth + 1) << "<title>" << escapedText(item->text(0))
+ << "</title>\n"
+ << indent(depth) << "</bookmark>\n";
+ } else if (tagName == "separator") {
+ out << indent(depth) << "<separator/>\n";
+ }
+}
diff --git a/examples/xml/saxbookmarks/xbelgenerator.h b/examples/xml/saxbookmarks/xbelgenerator.h
new file mode 100644
index 0000000000..84011a262f
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelgenerator.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELGENERATOR_H
+#define XBELGENERATOR_H
+
+#include <QTextStream>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+class XbelGenerator
+{
+public:
+ XbelGenerator(QTreeWidget *treeWidget);
+
+ bool write(QIODevice *device);
+
+private:
+ static QString indent(int indentLevel);
+ static QString escapedText(const QString &str);
+ static QString escapedAttribute(const QString &str);
+ void generateItem(QTreeWidgetItem *item, int depth);
+
+ QTreeWidget *treeWidget;
+ QTextStream out;
+};
+
+#endif
diff --git a/examples/xml/saxbookmarks/xbelhandler.cpp b/examples/xml/saxbookmarks/xbelhandler.cpp
new file mode 100644
index 0000000000..09874c9edc
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelhandler.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbelhandler.h"
+
+XbelHandler::XbelHandler(QTreeWidget *treeWidget)
+ : treeWidget(treeWidget)
+{
+ item = 0;
+ metXbelTag = false;
+
+ QStyle *style = treeWidget->style();
+
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
+}
+
+bool XbelHandler::startElement(const QString & /* namespaceURI */,
+ const QString & /* localName */,
+ const QString &qName,
+ const QXmlAttributes &attributes)
+{
+ if (!metXbelTag && qName != "xbel") {
+ errorStr = QObject::tr("The file is not an XBEL file.");
+ return false;
+ }
+
+ if (qName == "xbel") {
+ QString version = attributes.value("version");
+ if (!version.isEmpty() && version != "1.0") {
+ errorStr = QObject::tr("The file is not an XBEL version 1.0 file.");
+ return false;
+ }
+ metXbelTag = true;
+ } else if (qName == "folder") {
+ item = createChildItem(qName);
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ item->setIcon(0, folderIcon);
+ item->setText(0, QObject::tr("Folder"));
+ bool folded = (attributes.value("folded") != "no");
+ treeWidget->setItemExpanded(item, !folded);
+ } else if (qName == "bookmark") {
+ item = createChildItem(qName);
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ item->setIcon(0, bookmarkIcon);
+ item->setText(0, QObject::tr("Unknown title"));
+ item->setText(1, attributes.value("href"));
+ } else if (qName == "separator") {
+ item = createChildItem(qName);
+ item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
+ item->setText(0, QString(30, 0xB7));
+ }
+
+ currentText.clear();
+ return true;
+}
+
+bool XbelHandler::endElement(const QString & /* namespaceURI */,
+ const QString & /* localName */,
+ const QString &qName)
+{
+ if (qName == "title") {
+ if (item)
+ item->setText(0, currentText);
+ } else if (qName == "folder" || qName == "bookmark"
+ || qName == "separator") {
+ item = item->parent();
+ }
+ return true;
+}
+
+bool XbelHandler::characters(const QString &str)
+{
+ currentText += str;
+ return true;
+}
+
+bool XbelHandler::fatalError(const QXmlParseException &exception)
+{
+ QMessageBox::information(treeWidget->window(), QObject::tr("SAX Bookmarks"),
+ QObject::tr("Parse error at line %1, column %2:\n"
+ "%3")
+ .arg(exception.lineNumber())
+ .arg(exception.columnNumber())
+ .arg(exception.message()));
+ return false;
+}
+
+QString XbelHandler::errorString() const
+{
+ return errorStr;
+}
+
+QTreeWidgetItem *XbelHandler::createChildItem(const QString &tagName)
+{
+ QTreeWidgetItem *childItem;
+ if (item) {
+ childItem = new QTreeWidgetItem(item);
+ } else {
+ childItem = new QTreeWidgetItem(treeWidget);
+ }
+ childItem->setData(0, Qt::UserRole, tagName);
+ return childItem;
+}
diff --git a/examples/xml/saxbookmarks/xbelhandler.h b/examples/xml/saxbookmarks/xbelhandler.h
new file mode 100644
index 0000000000..cee1bafe48
--- /dev/null
+++ b/examples/xml/saxbookmarks/xbelhandler.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELHANDLER_H
+#define XBELHANDLER_H
+
+#include <QIcon>
+#include <QXmlDefaultHandler>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+class XbelHandler : public QXmlDefaultHandler
+{
+public:
+ XbelHandler(QTreeWidget *treeWidget);
+
+ bool startElement(const QString &namespaceURI, const QString &localName,
+ const QString &qName, const QXmlAttributes &attributes);
+ bool endElement(const QString &namespaceURI, const QString &localName,
+ const QString &qName);
+ bool characters(const QString &str);
+ bool fatalError(const QXmlParseException &exception);
+ QString errorString() const;
+
+private:
+ QTreeWidgetItem *createChildItem(const QString &tagName);
+
+ QTreeWidget *treeWidget;
+ QTreeWidgetItem *item;
+ QString currentText;
+ QString errorStr;
+ bool metXbelTag;
+
+ QIcon folderIcon;
+ QIcon bookmarkIcon;
+};
+
+#endif
diff --git a/examples/xml/streambookmarks/frank.xbel b/examples/xml/streambookmarks/frank.xbel
new file mode 100644
index 0000000000..6bd63b8b07
--- /dev/null
+++ b/examples/xml/streambookmarks/frank.xbel
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="yes">
+ <title>Literate Programming</title>
+ <bookmark href="http://www.vivtek.com/litprog.html">
+ <title>Synopsis of Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html">
+ <title>Literate Programming: Propaganda and Tools</title>
+ </bookmark>
+ <bookmark href="http://www.isy.liu.se/%7Eturbell/litprog/">
+ <title>Literate Programming by Henrik Turbell</title>
+ </bookmark>
+ <bookmark href="http://www.desy.de/user/projects/LitProg.html">
+ <title>Literate Programming Library</title>
+ </bookmark>
+ <bookmark href="http://www.loria.fr/services/tex/english/litte.html">
+ <title>Literate Programming Basics</title>
+ </bookmark>
+ <bookmark href="http://ei.cs.vt.edu/%7Ecs5014/courseNotes/4.LiterateProgramming/literate_prog.html">
+ <title>Literate Programming Overview</title>
+ </bookmark>
+ <bookmark href="http://www.perl.com/pub/a/tchrist/litprog.html">
+ <title>POD is not Literate Programming</title>
+ </bookmark>
+ <bookmark href="http://www.cornellcollege.edu/%7Eltabak/publications/articles/swsafety.html">
+ <title>Computers That We Can Count On</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/litpro/issues-and-problems.html">
+ <title>Literate Programming - Issues and Problems</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?LiterateProgramming">
+ <title>Literate Programming - Wiki Pages</title>
+ </bookmark>
+ <bookmark href="http://developers.slashdot.org/developers/02/05/19/2216233.shtml">
+ <title>What is well-commented code?</title>
+ </bookmark>
+ <bookmark href="http://liinwww.ira.uka.de/bibliography/SE/litprog.html">
+ <title>Bibliography on literate programming - A searchable bibliography</title>
+ </bookmark>
+ <bookmark href="http://www2.umassd.edu/SWPI/ProcessBibliography/bib-codereading.html">
+ <title>Program comprehension and code reading bibliography</title>
+ </bookmark>
+ <bookmark href="http://www.cs.auc.dk/%7Enormark/elucidative-programming/">
+ <title>Elucidative Programming</title>
+ </bookmark>
+ <bookmark href="http://www.msu.edu/%7Epfaffben/avl/index.html">
+ <title>AVL Trees (TexiWeb)</title>
+ </bookmark>
+ <bookmark href="http://literate-programming.wikiverse.org/">
+ <title>Literate Programming on Wikiverse</title>
+ </bookmark>
+ <bookmark href="http://www.pbrt.org/">
+ <title>Physically Based Rendering: From Theory to Implementation</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Useful C++ Links</title>
+ <folder folded="no">
+ <title>STL</title>
+ <bookmark href="http://www.sgi.com/tech/stl/table_of_contents.html">
+ <title>STL Reference Documentation</title>
+ </bookmark>
+ <bookmark href="http://www.yrl.co.uk/~phil/stl/stl.htmlx">
+ <title>STL Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.cppreference.com/cpp_stl.html">
+ <title>STL Reference</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Qt</title>
+ <bookmark href="http://qt.nokia.com/doc/2.3/">
+ <title>Qt 2.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/3.3/">
+ <title>Qt 3.3 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 Reference</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>Qt Home Page</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>IOStreams</title>
+ <bookmark href="http://www.cplusplus.com/ref/iostream/index.html">
+ <title>IO Stream Library</title>
+ </bookmark>
+ <bookmark href="http://courses.cs.vt.edu/~cs2604/fall01/binio.html">
+ <title>Binary I/O</title>
+ </bookmark>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/input-output.html">
+ <title>I/O Stream FAQ</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>gdb</title>
+ <bookmark href="http://www.cs.princeton.edu/~benjasik/gdb/gdbtut.html">
+ <title>GDB Tutorial</title>
+ </bookmark>
+ <bookmark href="http://www.gnu.org/manual/gdb-4.17/html_mono/gdb.html">
+ <title>Debugging with GDB</title>
+ </bookmark>
+ <bookmark href="http://www.cs.washington.edu/orgs/acm/tutorials/dev-in-unix/gdb-refcard.pdf">
+ <title>GDB Quick Reference Page (PDF) (Handy)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Classes and Constructors</title>
+ <bookmark href="http://www.parashift.com/c++-faq-lite/ctors.html">
+ <title>Constructor FAQ</title>
+ </bookmark>
+ <bookmark href="http://www.juicystudio.com/tutorial/cpp/index.html">
+ <title>Organizing Classes</title>
+ </bookmark>
+ </folder>
+ </folder>
+ <folder folded="yes">
+ <title>Software Documentation or System Documentation</title>
+ <bookmark href="http://www.martinfowler.com/distributedComputing/thud.html">
+ <title>The Almighty Thud</title>
+ </bookmark>
+ <bookmark href="http://msdn.microsoft.com/library/techart/cfr.htm">
+ <title>Microsoft Coding Techniques and Programming Practices</title>
+ </bookmark>
+ <bookmark href="http://www.bearcave.com/software/prog_docs.html">
+ <title>Software and Documentation</title>
+ </bookmark>
+ <bookmark href="http://c2.com/cgi/wiki?TheSourceCodeIsTheDesign">
+ <title>The Source Code is the Design</title>
+ </bookmark>
+ <bookmark href="http://www.bleading-edge.com/Publications/C++Journal/Cpjour2.htm">
+ <title>What is Software Design?</title>
+ </bookmark>
+ <bookmark href="http://www.mindprod.com/unmain.html">
+ <title>How To Write Unmaintainable Code</title>
+ </bookmark>
+ <bookmark href="http://www.idinews.com/selfDoc.html">
+ <title>Self Documenting Program Code Remains a Distant Goal</title>
+ </bookmark>
+ <bookmark href="http://www.sdmagazine.com/documents/s=730/sdm0106m/0106m.htm">
+ <title>Place Tab A in Slot B</title>
+ </bookmark>
+ <bookmark href="http://www.holub.com/class/uml/uml.html">
+ <title>UML Reference Card</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>TeX Resources</title>
+ <bookmark href="http://www.tug.org/">
+ <title>The TeX User's Group</title>
+ </bookmark>
+ <bookmark href="http://www.miktex.org/">
+ <title>MikTeX website</title>
+ </bookmark>
+ <bookmark href="http://cm.bell-labs.com/who/hobby/MetaPost.html">
+ <title>MetaPost website</title>
+ </bookmark>
+ <bookmark href="http://pauillac.inria.fr/%7Emaranget/hevea/">
+ <title>HEVEA is a quite complete and fast LATEX to HTML translator</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Portable Document Format (PDF)</title>
+ <bookmark href="http://www.adobe.com/">
+ <title>Adobe - The postscript and PDF standards</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html">
+ <title>Reference Manual Portable Document Format</title>
+ </bookmark>
+ <bookmark href="http://partners.adobe.com/asn/developer/acrosdk/main.html">
+ <title>Adobe Acrobat Software Development Kit</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Literature Sites</title>
+ <bookmark href="http://www.cc.columbia.edu/cu/libraries/subjects/speccol.html">
+ <title>Guide to Special Collections (Columbia University)</title>
+ </bookmark>
+ <bookmark href="http://www.ipl.org/ref/litcrit/">
+ <title>Literary Criticism on the Web from the Internet Public Library</title>
+ </bookmark>
+ <bookmark href="http://www.victorianweb.org/">
+ <title>Victorian Web.</title>
+ </bookmark>
+ <bookmark href="http://vos.ucsb.edu/">
+ <title>Voice of the Shuttle.</title>
+ </bookmark>
+ <bookmark href="http://www.modjourn.brown.edu/">
+ <title>Modernist Journals Project</title>
+ </bookmark>
+ <bookmark href="http://www.poetspath.com">
+ <title>Museum of American Poetics</title>
+ </bookmark>
+ <bookmark href="http://www.english.uiuc.edu/maps/">
+ <title>Modern American Poetry</title>
+ </bookmark>
+ <bookmark href="http://www.findarticles.com/">
+ <title>FindArticles.com</title>
+ </bookmark>
+ <bookmark href="http://www.literaryhistory.com">
+ <title>Literary History</title>
+ </bookmark>
+ <bookmark href="http://www.litencyc.com/LitEncycFrame.htm">
+ <title>Literary Encyclopedia</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://texts.cdlib.org/ucpress/">
+ <title>The University of California Press</title>
+ </bookmark>
+ <bookmark href="http://www.letrs.indiana.edu/web/w/wright2/">
+ <title>Wright American Fiction, 1851-1875</title>
+ </bookmark>
+ <bookmark href="http://docsouth.unc.edu/">
+ <title>Documenting the American South: Beginnings to 1920</title>
+ </bookmark>
+ <bookmark href="http://etext.lib.virginia.edu/eng-on.html">
+ <title>Electronic Text Center at the University of Virginia</title>
+ </bookmark>
+ <bookmark href="http://digital.nypl.org/schomburg/writers_aa19/">
+ <title>The Schomburg Center for Research in Black Culture</title>
+ </bookmark>
+ <bookmark href="http://www.infomotions.com/alex2/">
+ <title>Alex Catalogue of Electronic Texts.</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/streambookmarks/jennifer.xbel b/examples/xml/streambookmarks/jennifer.xbel
new file mode 100644
index 0000000000..36256fda0a
--- /dev/null
+++ b/examples/xml/streambookmarks/jennifer.xbel
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE xbel>
+<xbel version="1.0">
+ <folder folded="no">
+ <title>Qt Resources</title>
+ <folder folded="yes">
+ <title>Qt Partners</title>
+ <bookmark href="http://partners.trolltech.com/partners/training.html">
+ <title>Training Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/service.html">
+ <title>Consultants and System Integrators</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/tech.html">
+ <title>Technology Partners</title>
+ </bookmark>
+ <bookmark href="http://partners.trolltech.com/partners/resellers.html">
+ <title>Value Added Resellers (VARs)</title>
+ </bookmark>
+ </folder>
+ <folder folded="yes">
+ <title>Community Resources</title>
+ <bookmark href="http://www.qtforum.org/">
+ <title>QtForum.org</title>
+ </bookmark>
+ <bookmark href="http://www.digitalfanatics.org/projects/qt_tutorial/">
+ <title>The Independent Qt Tutorial</title>
+ </bookmark>
+ <bookmark href="http://prog.qt.free.fr/">
+ <title>French PROG.Qt</title>
+ </bookmark>
+ <bookmark href="http://www.qtforum.de/">
+ <title>German Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://www.korone.net/">
+ <title>Korean Qt Community Site</title>
+ </bookmark>
+ <bookmark href="http://prog.org.ru/forum/forum_14.html">
+ <title>Russian Qt Forum</title>
+ </bookmark>
+ <bookmark href="http://qt4.digitalfanatics.org/">
+ <title>Digitalfanatics: The QT 4 Resource Center</title>
+ </bookmark>
+ <bookmark href="http://www.qtquestions.org/">
+ <title>QtQuestions</title>
+ </bookmark>
+ </folder>
+ <bookmark href="http://qt.nokia.com/doc/qq/">
+ <title>Qt Quarterly</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/">
+ <title>Qt home page</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/doc/4.0/">
+ <title>Qt 4.0 documentation</title>
+ </bookmark>
+ <bookmark href="http://qt.nokia.com/developer/faqs/">
+ <title>Frequently Asked Questions</title>
+ </bookmark>
+ </folder>
+ <folder folded="no">
+ <title>Online Dictionaries</title>
+ <bookmark href="http://www.dictionary.com/">
+ <title>Dictionary.com</title>
+ </bookmark>
+ <bookmark href="http://www.m-w.com/">
+ <title>Merriam-Webster Online</title>
+ </bookmark>
+ <bookmark href="http://dictionary.cambridge.org/">
+ <title>Cambridge Dictionaries Online</title>
+ </bookmark>
+ <bookmark href="http://www.onelook.com/">
+ <title>OneLook Dictionary Search</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="www.iee.et.tu-dresden.de/">
+ <title>The New English-German Dictionary</title>
+ </bookmark>
+ <bookmark href="http://dict.tu-chemnitz.de/">
+ <title>TU Chemnitz German-English Dictionary</title>
+ </bookmark>
+ <separator/>
+ <bookmark href="http://atilf.atilf.fr/tlf.htm">
+ <title>Trésor de la Langue Française informatisé</title>
+ </bookmark>
+ <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/">
+ <title>Dictionnaire de l'Académie Française</title>
+ </bookmark>
+ <bookmark href="http://elsap1.unicaen.fr/cgi-bin/cherches.cgi">
+ <title>Dictionnaire des synonymes</title>
+ </bookmark>
+ </folder>
+</xbel>
diff --git a/examples/xml/streambookmarks/main.cpp b/examples/xml/streambookmarks/main.cpp
new file mode 100644
index 0000000000..c44e921e82
--- /dev/null
+++ b/examples/xml/streambookmarks/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow mainWin;
+ mainWin.show();
+ mainWin.open();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp
new file mode 100644
index 0000000000..e9236e93e6
--- /dev/null
+++ b/examples/xml/streambookmarks/mainwindow.cpp
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+#include "xbelreader.h"
+#include "xbelwriter.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QStringList labels;
+ labels << tr("Title") << tr("Location");
+
+ treeWidget = new QTreeWidget;
+ treeWidget->header()->setResizeMode(QHeaderView::Stretch);
+ treeWidget->setHeaderLabels(labels);
+ setCentralWidget(treeWidget);
+
+ createActions();
+ createMenus();
+
+ statusBar()->showMessage(tr("Ready"));
+
+ setWindowTitle(tr("QXmlStream Bookmarks"));
+ resize(480, 320);
+}
+//! [0]
+
+//! [1]
+void MainWindow::open()
+{
+ QString fileName =
+ QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ treeWidget->clear();
+
+
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ XbelReader reader(treeWidget);
+ if (!reader.read(&file)) {
+ QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
+ tr("Parse error in file %1:\n\n%2")
+ .arg(fileName)
+ .arg(reader.errorString()));
+ } else {
+ statusBar()->showMessage(tr("File loaded"), 2000);
+ }
+
+}
+//! [1]
+
+//! [2]
+void MainWindow::saveAs()
+{
+ QString fileName =
+ QFileDialog::getSaveFileName(this, tr("Save Bookmark File"),
+ QDir::currentPath(),
+ tr("XBEL Files (*.xbel *.xml)"));
+ if (fileName.isEmpty())
+ return;
+
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("QXmlStream Bookmarks"),
+ tr("Cannot write file %1:\n%2.")
+ .arg(fileName)
+ .arg(file.errorString()));
+ return;
+ }
+
+ XbelWriter writer(treeWidget);
+ if (writer.writeFile(&file))
+ statusBar()->showMessage(tr("File saved"), 2000);
+}
+//! [2]
+
+//! [3]
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About QXmlStream Bookmarks"),
+ tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's "
+ "QXmlStream classes to read and write XML documents."));
+}
+//! [3]
+
+//! [4]
+void MainWindow::createActions()
+{
+ openAct = new QAction(tr("&Open..."), this);
+ openAct->setShortcuts(QKeySequence::Open);
+ connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
+
+ saveAsAct = new QAction(tr("&Save As..."), this);
+ saveAsAct->setShortcuts(QKeySequence::SaveAs);
+ connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
+
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+
+ aboutAct = new QAction(tr("&About"), this);
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
+
+ aboutQtAct = new QAction(tr("About &Qt"), this);
+ connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+}
+//! [4]
+
+//! [5]
+void MainWindow::createMenus()
+{
+ fileMenu = menuBar()->addMenu(tr("&File"));
+ fileMenu->addAction(openAct);
+ fileMenu->addAction(saveAsAct);
+ fileMenu->addAction(exitAct);
+
+ menuBar()->addSeparator();
+
+ helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(aboutAct);
+ helpMenu->addAction(aboutQtAct);
+}
+//! [5]
diff --git a/examples/xml/streambookmarks/mainwindow.h b/examples/xml/streambookmarks/mainwindow.h
new file mode 100644
index 0000000000..f27c4088bc
--- /dev/null
+++ b/examples/xml/streambookmarks/mainwindow.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void open();
+ void saveAs();
+ void about();
+
+private:
+ void createActions();
+ void createMenus();
+
+ QTreeWidget *treeWidget;
+
+ QMenu *fileMenu;
+ QMenu *helpMenu;
+ QAction *openAct;
+ QAction *saveAsAct;
+ QAction *exitAct;
+ QAction *aboutAct;
+ QAction *aboutQtAct;
+};
+//! [0]
+
+#endif
diff --git a/examples/xml/streambookmarks/streambookmarks.pro b/examples/xml/streambookmarks/streambookmarks.pro
new file mode 100644
index 0000000000..febd3cd85f
--- /dev/null
+++ b/examples/xml/streambookmarks/streambookmarks.pro
@@ -0,0 +1,16 @@
+HEADERS = mainwindow.h \
+ xbelreader.h \
+ xbelwriter.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ xbelreader.cpp \
+ xbelwriter.cpp
+QT += xml
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/streambookmarks
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS streambookmarks.pro *.xbel
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/streambookmarks
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp
new file mode 100644
index 0000000000..e6d1c64e64
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelreader.cpp
@@ -0,0 +1,175 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbelreader.h"
+
+//! [0]
+XbelReader::XbelReader(QTreeWidget *treeWidget)
+ : treeWidget(treeWidget)
+{
+ QStyle *style = treeWidget->style();
+
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon),
+ QIcon::Normal, QIcon::Off);
+ folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon),
+ QIcon::Normal, QIcon::On);
+ bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon));
+}
+//! [0]
+
+//! [1]
+bool XbelReader::read(QIODevice *device)
+{
+ xml.setDevice(device);
+
+ if (xml.readNextStartElement()) {
+ if (xml.name() == "xbel" && xml.attributes().value("version") == "1.0")
+ readXBEL();
+ else
+ xml.raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
+ }
+
+ return !xml.error();
+}
+//! [1]
+
+//! [2]
+QString XbelReader::errorString() const
+{
+ return QObject::tr("%1\nLine %2, column %3")
+ .arg(xml.errorString())
+ .arg(xml.lineNumber())
+ .arg(xml.columnNumber());
+}
+//! [2]
+
+//! [3]
+void XbelReader::readXBEL()
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "xbel");
+
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "folder")
+ readFolder(0);
+ else if (xml.name() == "bookmark")
+ readBookmark(0);
+ else if (xml.name() == "separator")
+ readSeparator(0);
+ else
+ xml.skipCurrentElement();
+ }
+}
+//! [3]
+
+//! [4]
+void XbelReader::readTitle(QTreeWidgetItem *item)
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "title");
+
+ QString title = xml.readElementText();
+ item->setText(0, title);
+}
+//! [4]
+
+//! [5]
+void XbelReader::readSeparator(QTreeWidgetItem *item)
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "separator");
+
+ QTreeWidgetItem *separator = createChildItem(item);
+ separator->setFlags(item->flags() & ~Qt::ItemIsSelectable);
+ separator->setText(0, QString(30, 0xB7));
+ xml.skipCurrentElement();
+}
+//! [5]
+
+void XbelReader::readFolder(QTreeWidgetItem *item)
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "folder");
+
+ QTreeWidgetItem *folder = createChildItem(item);
+ bool folded = (xml.attributes().value("folded") != "no");
+ treeWidget->setItemExpanded(folder, !folded);
+
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "title")
+ readTitle(folder);
+ else if (xml.name() == "folder")
+ readFolder(folder);
+ else if (xml.name() == "bookmark")
+ readBookmark(folder);
+ else if (xml.name() == "separator")
+ readSeparator(folder);
+ else
+ xml.skipCurrentElement();
+ }
+}
+
+void XbelReader::readBookmark(QTreeWidgetItem *item)
+{
+ Q_ASSERT(xml.isStartElement() && xml.name() == "bookmark");
+
+ QTreeWidgetItem *bookmark = createChildItem(item);
+ bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable);
+ bookmark->setIcon(0, bookmarkIcon);
+ bookmark->setText(0, QObject::tr("Unknown title"));
+ bookmark->setText(1, xml.attributes().value("href").toString());
+
+ while (xml.readNextStartElement()) {
+ if (xml.name() == "title")
+ readTitle(bookmark);
+ else
+ xml.skipCurrentElement();
+ }
+}
+
+QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item)
+{
+ QTreeWidgetItem *childItem;
+ if (item) {
+ childItem = new QTreeWidgetItem(item);
+ } else {
+ childItem = new QTreeWidgetItem(treeWidget);
+ }
+ childItem->setData(0, Qt::UserRole, xml.name().toString());
+ return childItem;
+}
diff --git a/examples/xml/streambookmarks/xbelreader.h b/examples/xml/streambookmarks/xbelreader.h
new file mode 100644
index 0000000000..1ca1190235
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelreader.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XBELREADER_H
+#define XBELREADER_H
+
+#include <QIcon>
+#include <QXmlStreamReader>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class XbelReader
+{
+public:
+//! [1]
+ XbelReader(QTreeWidget *treeWidget);
+//! [1]
+
+ bool read(QIODevice *device);
+
+ QString errorString() const;
+
+private:
+//! [2]
+ void readXBEL();
+ void readTitle(QTreeWidgetItem *item);
+ void readSeparator(QTreeWidgetItem *item);
+ void readFolder(QTreeWidgetItem *item);
+ void readBookmark(QTreeWidgetItem *item);
+
+ QTreeWidgetItem *createChildItem(QTreeWidgetItem *item);
+
+ QXmlStreamReader xml;
+ QTreeWidget *treeWidget;
+//! [2]
+
+ QIcon folderIcon;
+ QIcon bookmarkIcon;
+};
+//! [0]
+
+#endif
diff --git a/examples/xml/streambookmarks/xbelwriter.cpp b/examples/xml/streambookmarks/xbelwriter.cpp
new file mode 100644
index 0000000000..bd5454c941
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelwriter.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "xbelwriter.h"
+
+//! [0]
+XbelWriter::XbelWriter(QTreeWidget *treeWidget)
+ : treeWidget(treeWidget)
+{
+ xml.setAutoFormatting(true);
+}
+//! [0]
+
+//! [1]
+bool XbelWriter::writeFile(QIODevice *device)
+{
+ xml.setDevice(device);
+
+ xml.writeStartDocument();
+ xml.writeDTD("<!DOCTYPE xbel>");
+ xml.writeStartElement("xbel");
+ xml.writeAttribute("version", "1.0");
+ for (int i = 0; i < treeWidget->topLevelItemCount(); ++i)
+ writeItem(treeWidget->topLevelItem(i));
+
+ xml.writeEndDocument();
+ return true;
+}
+//! [1]
+
+//! [2]
+void XbelWriter::writeItem(QTreeWidgetItem *item)
+{
+ QString tagName = item->data(0, Qt::UserRole).toString();
+ if (tagName == "folder") {
+ bool folded = !treeWidget->isItemExpanded(item);
+ xml.writeStartElement(tagName);
+ xml.writeAttribute("folded", folded ? "yes" : "no");
+ xml.writeTextElement("title", item->text(0));
+ for (int i = 0; i < item->childCount(); ++i)
+ writeItem(item->child(i));
+ xml.writeEndElement();
+ } else if (tagName == "bookmark") {
+ xml.writeStartElement(tagName);
+ if (!item->text(1).isEmpty())
+ xml.writeAttribute("href", item->text(1));
+ xml.writeTextElement("title", item->text(0));
+ xml.writeEndElement();
+ } else if (tagName == "separator") {
+ xml.writeEmptyElement(tagName);
+ }
+}
+//! [2]
diff --git a/examples/xml/streambookmarks/xbelwriter.h b/examples/xml/streambookmarks/xbelwriter.h
new file mode 100644
index 0000000000..8160a87b52
--- /dev/null
+++ b/examples/xml/streambookmarks/xbelwriter.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR 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 XBELWRITER_H
+#define XBELWRITER_H
+
+#include <QXmlStreamWriter>
+
+QT_BEGIN_NAMESPACE
+class QTreeWidget;
+class QTreeWidgetItem;
+QT_END_NAMESPACE
+
+//! [0]
+class XbelWriter
+{
+public:
+ XbelWriter(QTreeWidget *treeWidget);
+ bool writeFile(QIODevice *device);
+
+private:
+ void writeItem(QTreeWidgetItem *item);
+ QXmlStreamWriter xml;
+ QTreeWidget *treeWidget;
+};
+//! [0]
+
+#endif
diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro
new file mode 100644
index 0000000000..a6c8aa18b4
--- /dev/null
+++ b/examples/xml/xml.pro
@@ -0,0 +1,20 @@
+TEMPLATE = subdirs
+SUBDIRS = htmlinfo \
+ xmlstreamlint
+
+!contains(QT_CONFIG, no-gui) {
+ SUBDIRS += dombookmarks \
+ rsslisting \
+ saxbookmarks \
+ streambookmarks
+}
+
+symbian: SUBDIRS = htmlinfo saxbookmarks
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xml.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/xml/xmlstreamlint/main.cpp b/examples/xml/xmlstreamlint/main.cpp
new file mode 100644
index 0000000000..78f40f64fa
--- /dev/null
+++ b/examples/xml/xmlstreamlint/main.cpp
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QFile>
+#include <QStringList>
+#include <QTextStream>
+#include <QXmlStreamReader>
+
+/*
+ This class exists for the sole purpose of creating a translation context.
+*/
+class XmlStreamLint
+{
+public:
+ Q_DECLARE_TR_FUNCTIONS(XmlStreamLint)
+};
+
+int main(int argc, char *argv[])
+{
+ enum ExitCode
+ {
+ Success,
+ ParseFailure,
+ ArgumentError,
+ WriteError,
+ FileFailure
+ };
+
+ QCoreApplication app(argc, argv);
+
+ QTextStream errorStream(stderr);
+
+ if (argc != 2)
+ {
+ errorStream << XmlStreamLint::tr(
+ "Usage: xmlstreamlint <path to XML file>\n");
+ return ArgumentError;
+ }
+
+ QString inputFilePath(QCoreApplication::arguments().at(1));
+ QFile inputFile(inputFilePath);
+
+ if (!QFile::exists(inputFilePath))
+ {
+ errorStream << XmlStreamLint::tr(
+ "File %1 does not exist.\n").arg(inputFilePath);
+ return FileFailure;
+
+ } else if (!inputFile.open(QIODevice::ReadOnly)) {
+ errorStream << XmlStreamLint::tr(
+ "Failed to open file %1.\n").arg(inputFilePath);
+ return FileFailure;
+ }
+
+ QFile outputFile;
+ if (!outputFile.open(stdout, QIODevice::WriteOnly))
+ {
+ errorStream << XmlStreamLint::tr("Failed to open stdout.");
+ return WriteError;
+ }
+
+//! [0]
+ QXmlStreamReader reader(&inputFile);
+ QXmlStreamWriter writer(&outputFile);
+//! [0]
+
+//! [1]
+ while (!reader.atEnd())
+ {
+ reader.readNext();
+
+ if (reader.error())
+ {
+ errorStream << XmlStreamLint::tr(
+ "Error: %1 in file %2 at line %3, column %4.\n").arg(
+ reader.errorString(), inputFilePath,
+ QString::number(reader.lineNumber()),
+ QString::number(reader.columnNumber()));
+ return ParseFailure;
+//! [1]
+
+//! [2]
+ } else
+ writer.writeCurrentToken(reader);
+ }
+//! [2]
+
+ return Success;
+}
diff --git a/examples/xml/xmlstreamlint/xmlstreamlint.pro b/examples/xml/xmlstreamlint/xmlstreamlint.pro
new file mode 100644
index 0000000000..838ef042ab
--- /dev/null
+++ b/examples/xml/xmlstreamlint/xmlstreamlint.pro
@@ -0,0 +1,12 @@
+CONFIG += console
+QT -= gui
+QT += xml
+SOURCES += main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/xmlstreamlint
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlstreamlint.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/xml/xmlstreamlint
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)